11package config
22
33import (
4+ _ "embed"
45 "fmt"
5- "os"
6- "path/filepath"
76
87 "gopkg.in/yaml.v3"
98)
@@ -26,37 +25,19 @@ type TemplatesConfig struct {
2625 Presets map [string ][]Preset `yaml:"presets"`
2726}
2827
28+ //go:embed templates.yaml
29+ var templatesYAML string
30+
2931var cachedConfig * TemplatesConfig
3032
31- // LoadTemplatesConfig loads template configuration file
33+ // LoadTemplatesConfig loads template configuration from embedded file
3234func LoadTemplatesConfig () (* TemplatesConfig , error ) {
3335 if cachedConfig != nil {
3436 return cachedConfig , nil
3537 }
3638
37- // Get config file path
38- exePath , err := os .Executable ()
39- if err != nil {
40- return nil , fmt .Errorf ("failed to get executable path: %w" , err )
41- }
42-
43- exeDir := filepath .Dir (exePath )
44- configPath := filepath .Join (exeDir , "templates" , "templates.yaml" )
45-
46- // If not found in executable directory, try development path
47- if _ , err := os .Stat (configPath ); os .IsNotExist (err ) {
48- // Development environment
49- cwd , _ := os .Getwd ()
50- configPath = filepath .Join (cwd , "templates" , "templates.yaml" )
51- }
52-
53- data , err := os .ReadFile (configPath )
54- if err != nil {
55- return nil , fmt .Errorf ("failed to read templates config: %w" , err )
56- }
57-
5839 var config TemplatesConfig
59- if err := yaml .Unmarshal (data , & config ); err != nil {
40+ if err := yaml .Unmarshal ([] byte ( templatesYAML ) , & config ); err != nil {
6041 return nil , fmt .Errorf ("failed to parse templates config: %w" , err )
6142 }
6243
0 commit comments