Files
core/http/api/config.go
Jan Stabenow eb1cc37456 Add GoSRT & improvements (repo-merge)
Commits (Ingo Oppermann):
- Add experimental SRT connection stats and logs
- Hide /config/reload endpoint in reade-only mode
- Add SRT server
- Create v16 in go.mod
- Fix data races, tests, lint, and update dependencies
- Add trailing slash for routed directories (datarhei/restreamer#340)
- Allow relative URLs in content in static routes

Co-Authored-By: Ingo Oppermann <57445+ioppermann@users.noreply.github.com>
2022-06-23 22:13:58 +02:00

84 lines
1.9 KiB
Go

package api
import (
"time"
"github.com/datarhei/core/v16/config"
)
// ConfigData embeds config.Data
type ConfigData struct {
config.Data
}
// Config is the config returned by the API
type Config struct {
CreatedAt time.Time `json:"created_at"`
LoadedAt time.Time `json:"loaded_at"`
UpdatedAt time.Time `json:"updated_at"`
Config ConfigData `json:"config"`
Overrides []string `json:"overrides"`
}
// SetConfig embeds config.Data. It is used to send a new config to the server.
type SetConfig struct {
config.Data
}
// MergeTo merges a sent config into a config.Config
func (rscfg *SetConfig) MergeTo(cfg *config.Config) {
cfg.ID = rscfg.ID
cfg.Name = rscfg.Name
cfg.Address = rscfg.Address
cfg.CheckForUpdates = rscfg.CheckForUpdates
cfg.Log = rscfg.Log
cfg.DB = rscfg.DB
cfg.Host = rscfg.Host
cfg.API = rscfg.API
cfg.TLS = rscfg.TLS
cfg.Storage = rscfg.Storage
cfg.RTMP = rscfg.RTMP
cfg.SRT = rscfg.SRT
cfg.FFmpeg = rscfg.FFmpeg
cfg.Playout = rscfg.Playout
cfg.Debug = rscfg.Debug
cfg.Metrics = rscfg.Metrics
cfg.Sessions = rscfg.Sessions
cfg.Service = rscfg.Service
cfg.Router = rscfg.Router
}
// NewSetConfig converts a config.Config into a RestreamerSetConfig in order to prepopulate
// a RestreamerSetConfig with the current values. The uploaded config can have missing fields that
// will be filled with the current values after unmarshalling the JSON.
func NewSetConfig(cfg *config.Config) SetConfig {
data := SetConfig{
cfg.Data,
}
return data
}
// Unmarshal converts a config.Config to a RestreamerConfig.
func (c *Config) Unmarshal(cfg *config.Config) {
if cfg == nil {
return
}
configData := ConfigData{
cfg.Data,
}
c.CreatedAt = cfg.CreatedAt
c.LoadedAt = cfg.LoadedAt
c.UpdatedAt = cfg.UpdatedAt
c.Config = configData
c.Overrides = cfg.Overrides()
}
// ConfigError is used to return error messages when uploading a new config
type ConfigError map[string][]string