mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-11-28 08:30:23 +08:00
* refactor: move lib/policy/config to lib/config Signed-off-by: Xe Iaso <me@xeiaso.net> * refactor: don't set global loggers anymore Ref #864 You were right @kotx, it is a bad idea to set the global logger instance. Signed-off-by: Xe Iaso <me@xeiaso.net> * feat(config): add log sink support Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: update spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * chore(test): go mod tidy Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: update spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * docs(admin/policies): add logging block documentation Signed-off-by: Xe Iaso <me@xeiaso.net> * docs: update CHANGELOG Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(cmd/anubis): revert this change, it's meant to be its own PR Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: go mod tidy Signed-off-by: Xe Iaso <me@xeiaso.net> * test: add file logging smoke test Assisted-by: GLM 4.6 via Claude Code Signed-off-by: Xe Iaso <me@xeiaso.net> * fix: don't expose the old log file time format string Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidOpenGraphConfig = errors.New("config.OpenGraph: invalid OpenGraph configuration")
|
|
ErrOpenGraphTTLDoesNotParse = errors.New("config.OpenGraph: ttl does not parse as a Duration, see https://pkg.go.dev/time#ParseDuration (formatted like 5m -> 5 minutes, 2h -> 2 hours, etc)")
|
|
ErrOpenGraphMissingProperty = errors.New("config.OpenGraph: default opengraph tags missing a property")
|
|
)
|
|
|
|
type openGraphFileConfig struct {
|
|
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
|
|
TimeToLive string `json:"ttl" yaml:"ttl"`
|
|
Enabled bool `json:"enabled" yaml:"enabled"`
|
|
ConsiderHost bool `json:"considerHost" yaml:"enabled"`
|
|
}
|
|
|
|
type OpenGraph struct {
|
|
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
|
|
TimeToLive time.Duration `json:"ttl" yaml:"ttl"`
|
|
Enabled bool `json:"enabled" yaml:"enabled"`
|
|
ConsiderHost bool `json:"considerHost" yaml:"enabled"`
|
|
}
|
|
|
|
func (og *openGraphFileConfig) Valid() error {
|
|
var errs []error
|
|
|
|
if _, err := time.ParseDuration(og.TimeToLive); err != nil {
|
|
errs = append(errs, fmt.Errorf("%w: ParseDuration(%q) returned: %w", ErrOpenGraphTTLDoesNotParse, og.TimeToLive, err))
|
|
}
|
|
|
|
if len(og.Override) != 0 {
|
|
for _, tag := range []string{
|
|
"og:title",
|
|
} {
|
|
if _, ok := og.Override[tag]; !ok {
|
|
errs = append(errs, fmt.Errorf("%w: %s", ErrOpenGraphMissingProperty, tag))
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(errs) != 0 {
|
|
return errors.Join(ErrInvalidOpenGraphConfig, errors.Join(errs...))
|
|
}
|
|
|
|
return nil
|
|
}
|