config.go 580 Bytes
package config

import (
	"log"

	"github.com/caarlos0/env/v6"
	"github.com/joho/godotenv"
)

type Config struct {
	Secret struct {
		CLIENTID     string `env:"SECRET.CLIENTID"`
		CLIENTSECRET string `env:"SECRET.CLIENTSECRET"`
	}

	Header struct {
		Cookie    string `env:"HEADER.COOKIE"`
		UserAgent string `env:"HEADER.USERAGENT"`
	}
}

var Cfg *Config

func init() {
	err := godotenv.Load("./config/.env")
	if err != nil {
		log.Fatal("Load .env file failed.")
	}

	config := Config{}
	if err := env.Parse(&config); err != nil {
		log.Fatalf("%+v\n", err)
	}
	Cfg = &config
}