first commit
This commit is contained in:
39
models/settings.go
Normal file
39
models/settings.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user