123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- package doc
- import (
- "log"
- "os"
- )
- type EnvVar = struct {
- Name string
- CommonName string
- Value string
- Announce bool
- }
- var EnvList []*EnvVar = []*EnvVar{
- {
- Name: "PIXIVFE_DEV",
- CommonName: "development mode",
-
-
-
- },
- {
- Name: "PIXIVFE_HOST",
- CommonName: "TCP hostname",
-
-
-
- },
- {
- Name: "PIXIVFE_PORT",
- CommonName: "TCP port",
-
-
-
- },
- {
- Name: "PIXIVFE_UNIXSOCKET",
- CommonName: "UNIX socket path",
-
-
-
- },
- {
- Name: "PIXIVFE_TOKEN",
- CommonName: "Pixiv token",
-
-
-
-
-
- },
- {
- Name: "PIXIVFE_REQUESTLIMIT",
- CommonName: "limit number of request per 30 seconds",
-
-
-
-
-
- },
- {
- Name: "PIXIVFE_IMAGEPROXY",
- CommonName: "image proxy server",
- Value: BuiltinProxyUrl,
- Announce: true,
-
-
-
-
-
-
- },
- {
- Name: "PIXIVFE_USERAGENT",
- CommonName: "user agent",
- Value: "Mozilla/5.0 (Windows NT 10.0; rv:123.0) Gecko/20100101 Firefox/123.0",
-
-
-
- },
- {
- Name: "PIXIVFE_ACCEPTLANGUAGE",
- CommonName: "Accept-Language header",
- Value: "en-US,en;q=0.5",
-
-
-
- },
- }
- func CollectAllEnv() {
- for _, v := range EnvList {
- value, hasValue := os.LookupEnv(v.Name)
- if hasValue {
- v.Value = value
- v.Announce = true
- }
- }
- }
- func GetEnv(key string) string {
- value, _ := LookupEnv(key)
- return value
- }
- func LookupEnv(key string) (string, bool) {
- for _, v := range EnvList {
- if v.Name == key {
- return v.Value, v.Value != ""
- }
- }
- log.Panicf("Environment Variable Name not in `EnvironList`: %s", key)
- panic("Go's type system has no Void/noreturn type...")
- }
- func AnnounceAllEnv() {
- for _, v := range EnvList {
- if v.Announce {
- log.Printf("Set %s to: %s\n", v.CommonName, v.Value)
- }
- }
- }
|