40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type Settings struct {
|
|
PrimaryColor string `json:"primaryColor,omitempty"`
|
|
PrimaryColorText string `json:"primaryColorText,omitempty"`
|
|
SecondaryColor string `json:"secondaryColor,omitempty"`
|
|
SecondaryColorText string `json:"secondaryColorText,omitempty"`
|
|
Icon string `json:"icon,omitempty"`
|
|
DatabaseName string `json:"databaseName,omitempty"`
|
|
DatabaseToken string `json:"databaseToken,omitempty"`
|
|
}
|
|
|
|
func (s *Settings) DefaultQuasarSettings() {
|
|
s.DatabaseName = "members.dba"
|
|
s.PrimaryColor = "#1976d2"
|
|
s.PrimaryColorText = "#ffffff"
|
|
s.SecondaryColor = "#26a69a"
|
|
s.SecondaryColorText = "#ffffff"
|
|
}
|
|
|
|
// --- Implement driver.Valuer (for saving to DB)
|
|
func (s Settings) Value() (driver.Value, error) {
|
|
return json.Marshal(s)
|
|
}
|
|
|
|
// --- Implement sql.Scanner (for reading from DB)
|
|
func (s *Settings) Scan(value any) error {
|
|
bytes, ok := value.([]byte)
|
|
if !ok {
|
|
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
|
}
|
|
return json.Unmarshal(bytes, s)
|
|
}
|