Add server Options and rework flags a bit

This commit is contained in:
Pablu23
2024-06-04 20:45:45 +02:00
parent b46d00a873
commit dbe349d0e6
5 changed files with 213 additions and 100 deletions

View File

@@ -0,0 +1,60 @@
package server
import "time"
type Options struct {
Port int
Auth Optional[AuthOptions]
Tls Optional[TlsOptions]
UpdateInterval time.Duration
}
type Optional[v any] struct {
Enabled bool
value v
}
func (o *Optional[v]) Get() v {
return o.value
}
func (o *Optional[v]) Set(value v) {
o.value = value
o.Enabled = true
}
func (o *Optional[v]) Apply(apply func(*v)) {
o.Enabled = true
apply(&o.value)
}
type AuthType int
const (
Raw AuthType = iota
File
)
type AuthOptions struct {
// Secret Direct or Path to secret File
Secret string
LoadType AuthType
}
type TlsOptions struct {
CertPath string
KeyPath string
}
func NewDefaultOptions() Options {
return Options{
Port: 8080,
Auth: Optional[AuthOptions]{
Enabled: false,
},
Tls: Optional[TlsOptions]{
Enabled: false,
},
UpdateInterval: 15 * time.Minute,
}
}