Beispiel #1
0
func init() {
	sec := setting.Cfg.Section("database")
	var err error
	x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
		sec.Key("USER").String(),
		sec.Key("PASSWD").String(),
		sec.Key("HOST").String(),
		sec.Key("NAME").String()))
	if err != nil {
		log.FatalD(4, "Fail to init new engine: %v", err)
	}
	x.SetLogger(nil)
	x.SetMapper(core.GonicMapper{})

	if err = x.Sync(new(PkgInfo), new(PkgRef)); err != nil {
		log.FatalD(4, "Fail to sync database: %v", err)
	}

	numOfPackages, _ = x.Count(new(PkgInfo))
	c := cron.New()
	c.AddFunc("@every 5m", func() {
		numOfPackages, _ = x.Count(new(PkgInfo))
	})
	c.Start()
}
Beispiel #2
0
func init() {
	log.Prefix = "[Go Walker]"

	sources := []interface{}{"conf/app.ini"}
	if com.IsFile("custom/app.ini") {
		sources = append(sources, "custom/app.ini")
	}

	var err error
	Cfg, err = macaron.SetConfig(sources[0], sources[1:]...)
	if err != nil {
		log.FatalD(4, "Fail to set configuration: %v", err)
	}

	if Cfg.Section("").Key("RUN_MODE").String() == "prod" {
		ProdMode = true
		macaron.Env = macaron.PROD
		macaron.ColorLog = false
	}

	sec := Cfg.Section("server")
	HTTPPort = sec.Key("HTTP_PORT").MustInt(8080)
	FetchTimeout = time.Duration(sec.Key("FETCH_TIMEOUT").MustInt(60)) * time.Second
	DocsJsPath = sec.Key("DOCS_JS_PATH").MustString("raw/docs/")
	DocsGobPath = sec.Key("DOCS_GOB_PATH").MustString("raw/gob/")

	GitHubCredentials = "client_id=" + Cfg.Section("github").Key("CLIENT_ID").String() +
		"&client_secret=" + Cfg.Section("github").Key("CLIENT_SECRET").String()

}
Beispiel #3
0
func main() {
	log.Info("Go Walker %s", APP_VER)
	log.Info("Run Mode: %s", strings.Title(macaron.Env))

	m := newMacaron()
	m.Get("/", routers.Home)
	m.Get("/search", routers.Search)
	m.Get("/search/json", routers.SearchJSON)

	m.Group("/api", func() {
		m.Group("/v1", func() {
			m.Get("/badge", apiv1.Badge)
		})
	})

	m.Get("/robots.txt", func() string {
		return `User-agent: *
Disallow: /search`
	})
	m.Get("/*", routers.Docs)

	listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort)
	log.Info("Listen: http://%s", listenAddr)
	if err := http.ListenAndServe(listenAddr, m); err != nil {
		log.FatalD(4, "Fail to start server: %v", err)
	}
}