mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-10 06:35:41 +01:00
Syndicate is working! Instagra & Pixelfed demonstrated with the new post attached. Lots of TODOs, but functional enough :)
33 lines
731 B
Go
33 lines
731 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func GetStrings(config map[string]any, fields ...string) (map[string]string, error) {
|
|
out := make(map[string]string)
|
|
for _, field := range fields {
|
|
name := field
|
|
val, ok := config[field].(string)
|
|
if !ok || val == "" {
|
|
return nil, fmt.Errorf("missing '%s' config field", field)
|
|
}
|
|
|
|
if strings.HasSuffix(field, "_envvar") {
|
|
name = strings.TrimSuffix(field, "_envvar")
|
|
envVal := val
|
|
if val, ok = os.LookupEnv(envVal); !ok {
|
|
return nil, fmt.Errorf("missing '%s' environment variable (for '%s' config field)", envVal, field)
|
|
}
|
|
}
|
|
|
|
if val == "" {
|
|
return nil, fmt.Errorf("empty '%s' config field", field)
|
|
}
|
|
|
|
out[name] = val
|
|
}
|
|
return out, nil
|
|
}
|