You've already forked img-proxy-url-generator
This commit is contained in:
43
config/generator.go
Normal file
43
config/generator.go
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user