golib/gconfig/http.go

31 lines
651 B
Go
Raw Normal View History

2023-06-15 21:22:51 +08:00
//
// http.go
// Copyright (C) 2022 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package gconfig
import "path/filepath"
type HttpConfig struct {
Addr string `yaml:"addr"`
Env string `yaml:"env"`
Debug bool `yaml:"debug"`
Storage string `yaml:"storage"` // 存储文件的目录。如果不是绝对路径,前面的 "./" 也不需要
}
func (c HttpConfig) GetBaseDir() string {
dir, _ := filepath.Abs("./")
return dir
}
// 全路径的 storage dir
func (c HttpConfig) GetStorageDir() string {
if c.Storage[0] == '/' {
return c.Storage
}
return filepath.Join(c.GetBaseDir(), "/", c.Storage)
}