jx/internal/config/generic.go
Matthew Rich 1460d2285b
Some checks failed
Declarative Tests / build-ubuntu-focal (push) Waiting to run
Lint / golangci-lint (push) Failing after 15s
Declarative Tests / test (push) Failing after 5s
Declarative Tests / build-fedora (push) Has been cancelled
add support for configuration documents
2024-07-01 14:54:18 -07:00

49 lines
888 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package config
import (
"context"
"encoding/json"
"net/url"
)
func init() {
ConfigTypes.Register([]string{"generic"}, func(u *url.URL) Configuration {
g := NewGeneric()
return g
})
}
type Generic map[string]any
func NewGeneric() *Generic {
g := make(Generic)
return &g
}
func (g *Generic) Clone() Configuration {
jsonGeneric, _ := json.Marshal(g)
clone := make(Generic)
if unmarshalErr := json.Unmarshal(jsonGeneric, &clone); unmarshalErr != nil {
panic(unmarshalErr)
}
return &clone
}
func (g *Generic) Type() string {
return "generic"
}
func (g *Generic) Read(context.Context) ([]byte, error) {
return nil, nil
}
func (g *Generic) GetValue(name string) (result any, err error) {
var ok bool
if result, ok = (*g)[name]; !ok {
err = ErrUnknownConfigurationKey
}
return
}