示例#1
0
文件: main.go 项目: hjin-me/HJinBlog
func install() {
	f, err := filepath.Abs("conf")
	if err != nil {
		panic(err)
	}
	banana.SetBaseDir(f)

	cfg := Conf{}

	_, err = banana.Config("app.yaml", &cfg)
	if err != nil {
		panic(err)
	}
	err = da.Create(cfg.MySQL)
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("database connected")
	err = CreateUser()
	if err != nil {
		panic(err)
	}
	err = CreateCategories()
	if err != nil {
		panic(err)
	}
	err = importPosts()
	if err != nil {
		panic(err)
	}
	defer da.Close()
}
示例#2
0
文件: route.go 项目: hjin-me/HJinBlog
func Handle() {
	rawConf := config{}
	_, err := banana.Config("routes.yaml", &rawConf)
	if err != nil {
		panic(err)
	}
	for _, r := range rawConf.Routes {
		for _, m := range r.Method {
			act, ok := actionList[r.Action]
			if !ok {
				panic(ErrActionNotFound)
			}
			switch m {
			case "POST":
				banana.Post(r.Rule, act)
			case "GET":
				banana.Get(r.Rule, act)
			case "PUT":
				banana.Put(r.Rule, act)
			case "DELETE":
				banana.Delete(r.Rule, act)
			case "OPTION":
				banana.Option(r.Rule, act)
			}
		}
	}
}
示例#3
0
文件: user.go 项目: hjin-me/HJinBlog
func getSalt() string {
	once.Do(func() {
		cfg := struct {
			Salt string `yaml:"salt"`
		}{}
		_, err := banana.Config("security.yaml", &cfg)
		if err != nil {
			panic(err)
		}
		gSalt = cfg.Salt
	})
	return gSalt
}
示例#4
0
文件: theme.go 项目: hjin-me/HJinBlog
func loadCfg() Config {
	once.Do(func() {
		banana.Config("theme.yaml", &globalCfg)
	})
	return globalCfg
}