feat: set up project
This commit is contained in:
48
kit/cfg/config.go
Normal file
48
kit/cfg/config.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
LogFile bool `required:"false" split_words:"true"`
|
||||
Host string `required:"true" split_words:"true"`
|
||||
DbAddress string `required:"true" split_words:"true"`
|
||||
DbName string `required:"true" split_words:"true"`
|
||||
OrdersCollection string `required:"true" split_words:"true"`
|
||||
RpcZmq string `required:"true" split_words:"true"`
|
||||
RpcAuth string `required:"true" split_words:"true"`
|
||||
RpcHost string `required:"true" split_words:"true"`
|
||||
WalletAddress string `required:"true" split_words:"true"`
|
||||
ApiPort string `required:"true" split_words:"true"`
|
||||
Views string `required:"true" split_words:"true"`
|
||||
ConversorApi string `required:"true" split_words:"true"`
|
||||
DollarRateApi string `required:"true" split_words:"true"`
|
||||
MailHost string `required:"true" split_words:"true"`
|
||||
MailPort string `required:"true" split_words:"true"`
|
||||
MailUser string `required:"true" split_words:"true"`
|
||||
MailPassword string `required:"true" split_words:"true"`
|
||||
MailFrom string `required:"true" split_words:"true"`
|
||||
MailTemplatesDir string `required:"true" split_words:"true"`
|
||||
MailTo string `required:"false" split_words:"true"`
|
||||
}
|
||||
|
||||
func NewConfig(envFile string) *Config {
|
||||
if envFile != "" {
|
||||
err := godotenv.Load(envFile)
|
||||
if err != nil {
|
||||
log.Fatalln("godotenv.Load:", err)
|
||||
}
|
||||
}
|
||||
|
||||
cfg := &Config{}
|
||||
err := envconfig.Process("", cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("envconfig.Process: %s\n", err)
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
16
kit/http.go
Normal file
16
kit/http.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package kit
|
||||
|
||||
import "net/http"
|
||||
|
||||
const JsonHeader = "application/json"
|
||||
|
||||
func WithJSONHeaders(r *http.Request) {
|
||||
r.Header.Add("Accept", JsonHeader)
|
||||
r.Header.Add("Content-Type", JsonHeader)
|
||||
}
|
||||
|
||||
func WithHeaders(r *http.Request, headers map[string]string) {
|
||||
for k, v := range headers {
|
||||
r.Header.Add(k, v)
|
||||
}
|
||||
}
|
||||
9
kit/path.go
Normal file
9
kit/path.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package kit
|
||||
|
||||
import (
|
||||
root_dir "gitea.urkob.com/urko/go-root-dir"
|
||||
)
|
||||
|
||||
func RootDir() string {
|
||||
return root_dir.RootDir("btc-pay-checker")
|
||||
}
|
||||
Reference in New Issue
Block a user