Feature: Added config file

This commit is contained in:
VnPower 2023-05-18 20:18:44 +07:00
parent 0f5567efbb
commit 5fc793ac21
Signed by: vnpower
GPG key ID: 881DE3DEB966106C
4 changed files with 40 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.vercel
*.map
config.yml

6
config.example.yml Normal file
View file

@ -0,0 +1,6 @@
# This is required for the API. See https://github.com/Nandaka/PixivUtil2/wiki#pixiv-login-using-cookie
# Please keep this carefully, there is a risk of account theft if somebody got your cookie.
# It is better to use a decoy account, instead of using your main account's cookie.
PHPSESSID:
userAgent: Mozilla/5.0

29
configs/config.go Normal file
View file

@ -0,0 +1,29 @@
package configs
import (
"embed"
"gopkg.in/yaml.v3"
"os"
)
var Config embed.FS
var Configs Conf
type Conf struct {
PHPSESSID string `yaml:"PHPSESSID"`
userAgent int `yaml:"userAgent"`
}
func (conf *Conf) ReadConfig() {
f, err := os.Open("config.yml")
if err != nil {
panic(err)
}
defer f.Close()
decoder := yaml.NewDecoder(f)
err = decoder.Decode(conf)
if err != nil {
panic(err)
}
}

View file

@ -2,6 +2,7 @@ package main
import (
"html/template"
"pixivfe/configs"
"pixivfe/views"
"github.com/gin-gonic/gin"
@ -31,6 +32,9 @@ func setupRouter() *gin.Engine {
}
func main() {
configs.Configs.ReadConfig()
println(configs.Configs.PHPSESSID)
r := setupRouter()
r.Run(":8080")