3 Star 0 Fork 0

Gitee 极速下载/lfs-test-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/github/lfs-test-server
克隆/下载
config.go 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"fmt"
"os"
"reflect"
"strings"
)
// Configuration holds application configuration. Values will be pulled from
// environment variables, prefixed by keyPrefix. Default values can be added
// via tags.
type Configuration struct {
Listen string `config:"tcp://:8080"`
Host string `config:"localhost:8080"`
ExtOrigin string `config:""` // consider lfs-test-server may behind a reverse proxy
MetaDB string `config:"lfs.db"`
ContentPath string `config:"lfs-content"`
AdminUser string `config:""`
AdminPass string `config:""`
Cert string `config:""`
Key string `config:""`
Scheme string `config:"http"`
Public string `config:"public"`
UseTus string `config:"false"`
TusHost string `config:"localhost:1080"`
}
func (c *Configuration) IsHTTPS() bool {
return strings.Contains(Config.Scheme, "https")
}
func (c *Configuration) IsPublic() bool {
switch Config.Public {
case "1", "true", "TRUE":
return true
}
return false
}
func (c *Configuration) IsUsingTus() bool {
switch Config.UseTus {
case "1", "true", "TRUE":
return true
}
return false
}
// Config is the global app configuration
var Config = &Configuration{}
const keyPrefix = "LFS"
func init() {
te := reflect.TypeOf(Config).Elem()
ve := reflect.ValueOf(Config).Elem()
for i := 0; i < te.NumField(); i++ {
sf := te.Field(i)
name := sf.Name
field := ve.FieldByName(name)
envVar := strings.ToUpper(fmt.Sprintf("%s_%s", keyPrefix, name))
env := os.Getenv(envVar)
tag := sf.Tag.Get("config")
if env == "" && tag != "" {
env = tag
}
field.SetString(env)
}
if port := os.Getenv("PORT"); port != "" {
// If $PORT is set, override LFS_LISTEN. This is useful for deploying to Heroku.
Config.Listen = "tcp://:" + port
}
if Config.ExtOrigin == "" {
Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/lfs-test-server.git
git@gitee.com:mirrors/lfs-test-server.git
mirrors
lfs-test-server
lfs-test-server
main

搜索帮助