diff --git a/data.go b/data.go index ad51683..4fcb8a7 100644 --- a/data.go +++ b/data.go @@ -27,60 +27,60 @@ type ConfigData interface { } type Config struct { - Image string `json:"image"` - Description string `json:"description"` - Person *Person `json:"person"` - Color *Color `json:"colors"` - Links []*Link `json:"links"` - Legal *Legal `json:"legal"` - CustomPages []string `json:"custom_pages"` + Image string `json:"image" toml:"image"` + Description string `json:"description" toml:"description"` + Person *Person `json:"person" toml:"person"` + Color *Color `json:"colors" toml:"colors"` + Links []*Link `json:"links" toml:"links"` + Legal *Legal `json:"legal" toml:"legal"` + CustomPages []string `json:"custom_pages" toml:"custom_pages"` } type Person struct { - Name string `json:"name"` - Pronouns string `json:"pronouns"` - Image string `json:"image"` - Tags []*Tag `json:"tags"` + Name string `json:"name" toml:"name"` + Pronouns string `json:"pronouns" toml:"pronouns"` + Image string `json:"image" toml:"image"` + Tags []*Tag `json:"tags" toml:"tags"` } type Tag struct { - Name string `json:"name"` - Description string `json:"description"` - Link string `json:"link"` + Name string `json:"name" toml:"name"` + Description string `json:"description" toml:"description"` + Link string `json:"link" toml:"link"` } type Color struct { - Background *BackgroundColor `json:"background"` - Button *ButtonColor `json:"buttons"` - Text string `json:"text"` - TagHover string `json:"tag_hover"` + Background *BackgroundColor `json:"background" toml:"background"` + Button *ButtonColor `json:"buttons" toml:"buttons"` + Text string `json:"text" toml:"text"` + TagHover string `json:"tag_hover" toml:"tag_hover"` } type BackgroundColor struct { - Type string `json:"type"` - Angle uint `json:"angle"` + Type string `json:"type" toml:"type"` + Angle uint `json:"angle" toml:"angle"` Colors []struct { - Color string `json:"color"` - Position uint `json:"position"` + Color string `json:"color" toml:"color"` + Position uint `json:"position" toml:"position"` } `json:"colors"` } type ButtonColor struct { - Text string `json:"text"` - TextHover string `json:"text_hover"` - Background string `json:"background"` - BackgroundHover string `json:"background_hover"` + Text string `json:"text" toml:"text"` + TextHover string `json:"text_hover" toml:"text_hover"` + Background string `json:"background" toml:"background"` + BackgroundHover string `json:"background_hover" toml:"background_hover"` } type Link struct { - Link string `json:"link"` - Content string `json:"content"` + Link string `json:"link" toml:"link"` + Content string `json:"content" toml:"content"` } type Legal struct { - LegalInformationLink string `json:"legal_information_link"` - ImagesSource []string `json:"images_source"` - FontSource string `json:"font_source"` + LegalInformationLink string `json:"legal_information_link" toml:"legal_information_link"` + ImagesSource []string `json:"images_source" toml:"images_source"` + FontSource string `json:"font_source" toml:"font_source"` } func (c *Config) GetBackground() template.CSS { @@ -96,17 +96,17 @@ func (c *Config) GetTextColor() template.CSS { } type CustomPage struct { - Title string `json:"title"` - URI string `json:"uri"` - Image string `json:"image"` - Description string `json:"description"` - Color *Color `json:"colors"` - Content []*CustomContent `json:"content"` + Title string `json:"title" toml:"title"` + URI string `json:"uri" toml:"uri"` + Image string `json:"image" toml:"image"` + Description string `json:"description" toml:"description"` + Color *Color `json:"colors" toml:"colors"` + Content []*CustomContent `json:"content" toml:"content"` } type CustomContent struct { - Type string `json:"type"` - Content string `json:"content"` + Type string `json:"type" toml:"type"` + Content string `json:"content" toml:"content"` } type Content interface { diff --git a/go.mod b/go.mod index ab5925e..9ba7e3c 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,9 @@ module now go 1.24 -require github.com/anhgelus/golatt v0.4.0 +require ( + github.com/BurntSushi/toml v1.4.0 + github.com/anhgelus/golatt v0.4.0 +) require github.com/gorilla/mux v1.8.1 // indirect diff --git a/go.sum b/go.sum index 287fb8f..5898685 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,6 @@ -github.com/anhgelus/golatt v0.1.0 h1:Lb6wCtbOmIE/p/wlDeFzuFuR++twPx+fHMNVDGhqjXk= -github.com/anhgelus/golatt v0.1.0/go.mod h1:Lgyy/Tm9A3w1ft72mZOUxl/p+4G2/WB3qxoXTv7Y4y8= -github.com/anhgelus/golatt v0.2.0 h1:tdgrx3K61mVYBMy9CNhTheSIV8lPWBl/JjeDIHmz9eg= -github.com/anhgelus/golatt v0.2.0/go.mod h1:Lgyy/Tm9A3w1ft72mZOUxl/p+4G2/WB3qxoXTv7Y4y8= -github.com/anhgelus/golatt v0.3.0 h1:HjolihJ+S9egfTXcbk3YBfxBKmEcEraUsqCsrPXzHOU= -github.com/anhgelus/golatt v0.3.0/go.mod h1:Lgyy/Tm9A3w1ft72mZOUxl/p+4G2/WB3qxoXTv7Y4y8= -github.com/anhgelus/golatt v0.3.1-0.20250224013601-7215f78c2860 h1:Xi1aqbDU1sr/8pJEun4sjOqz5PPQc7hVSR1kuCiRgTE= -github.com/anhgelus/golatt v0.3.1-0.20250224013601-7215f78c2860/go.mod h1:Lgyy/Tm9A3w1ft72mZOUxl/p+4G2/WB3qxoXTv7Y4y8= -github.com/anhgelus/golatt v0.3.1-0.20250224134406-139fb679dfbe h1:5tOWGCqgDHY3zxdTYBLAjmRhwVJBeBobf+4TJTLB8II= -github.com/anhgelus/golatt v0.3.1-0.20250224134406-139fb679dfbe/go.mod h1:yC4OU6rMSbHKsfcvN7jYSyGsnpbivHKDGVFohZI5VH4= -github.com/anhgelus/golatt v0.3.1-0.20250224140223-d0258a5fba9f h1:SwvbWm/6oeHs8KzadqC3P3mFTgilkMZz2O5Glxtsq6s= -github.com/anhgelus/golatt v0.3.1-0.20250224140223-d0258a5fba9f/go.mod h1:yC4OU6rMSbHKsfcvN7jYSyGsnpbivHKDGVFohZI5VH4= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/anhgelus/golatt v0.4.0 h1:EZIBHtWMpwhJwMEzTSUNgieqWwHPtlBpKQ4idSjWqRA= +github.com/anhgelus/golatt v0.4.0/go.mod h1:yC4OU6rMSbHKsfcvN7jYSyGsnpbivHKDGVFohZI5VH4= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/main.go b/main.go index 8a960f6..80c83d8 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,12 @@ import ( "embed" "encoding/json" "flag" + "github.com/BurntSushi/toml" "github.com/anhgelus/golatt" "log/slog" "net/http" "os" + "strings" ) var ( @@ -49,8 +51,15 @@ func main() { if err != nil { panic(err) } + var cfg Config - err = json.Unmarshal(b, &cfg) + if strings.HasSuffix(configPath, ".json") { + err = json.Unmarshal(b, &cfg) + } else if strings.HasSuffix(configPath, ".toml") { + err = toml.Unmarshal(b, &cfg) + } else { + panic("config file must be .json or .toml") + } if err != nil { panic(err) } @@ -58,6 +67,7 @@ func main() { if err != nil { panic(err) } + var g *golatt.Golatt if dev { g = golatt.New(golatt.UsableEmbedFS("templates", templates), os.DirFS("public"), os.DirFS("dist"))