func (app *App) init(cfg config.Config) { dbCfg := cfg.GetSection("database") host := dbCfg.GetStr("host") port := dbCfg.GetInt16("port") user := dbCfg.GetStr("username") pass := dbCfg.GetStr("password") dbname := dbCfg.GetStr("dbname") log.Printf("connect mysql: host=%s, port=%d, user=%s, pass=%s, dbname=%s", host, port, user, pass, dbname) db.Open(host, port, user, pass, dbname) }
func main() { var conf config.Config err := conf.ParseDir("config") if err != nil { log.Fatal(err) } var dataStore datastore.DataStore dataStore.Init() go server.Run(&conf, &dataStore) select {} }
func (server *Server) Start() { var config = new(config.Config) ok := config.Parse() if ok { for key, channel := range config.Channels { fmt.Printf("K %s", key) http.Handle("/"+channel, websocket.Handler(ChannelHandler)) } err := http.ListenAndServe(":"+config.Port, nil) if err != nil { panic("ListenAndServe: ", err.String()) } } }
// Inits and sets up the CLI options with defaults // @params {nil} // @return {Options} - returns the Options struct func (o Options) Init() Options { // get our local config holding our defaults configuration := new(config.Config).Init() configData := configuration.GetAll() // setup our flags binding the pointer to variables of := flag.String("file", configData.DefaultFile, "Path and filename to process (e.g. files/list.csv)") oc := flag.Int("column", configData.UrlColumn, "Column where the URL is at") flag.Parse() // update and return struct o.file = *of o.column = *oc return o }
func NewApp(cfg config.Config) (*App, error) { app := new(App) app.cfg = cfg app.users = make(map[int32]*UserSession) app.sessionMapping = make(map[int32]int32) app.events = make(chan anet.Event, MAXN_EXTERNAL_EVENTS) netCfg := cfg.GetSection("network") listenSection := netCfg.GetSection("listen") addr := listenSection.GetStr("4client") log.Printf("init network %s for %s ok.", "4client", addr) app.server = anet.NewServer("tcp4", addr, protocol.Proto{}, app.events) app.init(cfg) return app, nil }