Example #1
0
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()
}
Example #2
0
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)
			}
		}
	}
}
Example #3
0
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
}
Example #4
0
func loadCfg() Config {
	once.Do(func() {
		banana.Config("theme.yaml", &globalCfg)
	})
	return globalCfg
}