package main

import (
	"sparrow/pkg/generator"
	"sparrow/pkg/server"
	"sparrow/services/knowoapi/model"

	"github.com/kataras/iris"
)

func main() {

	err := server.Init("knowoapi")
	if err != nil {
		server.Log.Fatal(err)
		return
	}

	//iris init

	app := iris.New()
	db, err := getDB()
	if err != nil {
		server.Log.Fatal(err)
	}
	models := new(model.All).Init(db)

	gen, err := generator.NewKeyGenerator(*confAESKey)
	if err != nil {
		server.Log.Fatal(err)
	}
	registerErrors(app)
	//注册路由
	registerRouters(app, models, gen)
	app.Build()
	// register a http handler
	err = server.RegisterHTTPHandler(app)
	if err != nil {
		server.Log.Errorf("RegisterHTTPHandler Error: %s", err)
		return
	}
	// go
	err = server.Run()
	if err != nil {
		server.Log.Fatal(err)
	}
}
