Files
img-proxy-url-generator/config/generator.go
Ron Rise 85938a2def
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 1m27s
Code re-organization
2025-01-26 18:20:45 -05:00

44 lines
889 B
Go

package config
import (
"fmt"
"github.com/bigkevmcd/go-configparser"
)
type generatorConfig struct {
Salt []byte
Key []byte
Host string
EncryptionKey string
PlainUrl bool
}
func getGeneratorConfig(p *configparser.ConfigParser) (*generatorConfig, error) {
var config string
var err error
gc := &generatorConfig{}
if !p.HasSection("img-proxy") {
return nil, fmt.Errorf("config error - [img-proxy] config required")
}
config, _ = p.Get("img-proxy", "key")
gc.Key = []byte(config)
config, _ = p.Get("img-proxy", "salt")
gc.Salt = []byte(config)
if config, err = p.Get("img-proxy", "host"); err != nil {
return nil, err
}
gc.Host = config
config, _ = p.Get("img-proxy", "plain-url")
gc.PlainUrl = config == "true" || config == "1"
config, _ = p.Get("img-proxy", "encryption-key")
gc.EncryptionKey = config
return gc, nil
}