diff --git a/.gitignore b/.gitignore index 82a084b50d..92b579f228 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ gogs *.exe *.exe~ +.DS_Store \ No newline at end of file diff --git a/conf/app.ini b/conf/app.ini index f70745d285..9d56816bb9 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1 +1,5 @@ -APP_NAME = Go Git Service \ No newline at end of file +APP_NAME = Go Git Service + +[server] +HTTP_ADDR = +HTTP_PORT = 3000 \ No newline at end of file diff --git a/gogs.go b/gogs.go index 8a4b9e0003..c0b11fb86e 100644 --- a/gogs.go +++ b/gogs.go @@ -5,15 +5,37 @@ package main import ( + "fmt" + "net/http" + "github.com/codegangsta/martini" + "github.com/martini-contrib/render" "github.com/gogits/gogs/routers" + "github.com/gogits/gogs/utils" + "github.com/gogits/gogs/utils/log" ) const APP_VER = "0.0.0.0212" -func main() { - m := martini.Classic() - m.Get("/", routers.HomeGet) - m.Run() +func init() { + +} + +func main() { + log.Info("App Name: %s", utils.Cfg.MustValue("", "APP_NAME")) + + m := martini.Classic() + + // Middleware. + m.Use(render.Renderer()) + + // Routers. + m.Get("/", routers.Home) + + listenAddr := fmt.Sprintf("%s:%s", + utils.Cfg.MustValue("server", "HTTP_ADDR"), + utils.Cfg.MustValue("server", "HTTP_PORT", "3000")) + log.Info("Listen: %s", listenAddr) + http.ListenAndServe(listenAddr, m) } diff --git a/routers/home.go b/routers/home.go index 5bb12f6ddd..ec7077d804 100644 --- a/routers/home.go +++ b/routers/home.go @@ -4,6 +4,10 @@ package routers -func HomeGet() string { - return "Hello world!" +import ( + "github.com/martini-contrib/render" +) + +func Home(r render.Render) { + r.HTML(200, "home", map[string]interface{}{}) } diff --git a/templates/base/base.tmpl b/templates/base/base.tmpl new file mode 100644 index 0000000000..2a28b79114 --- /dev/null +++ b/templates/base/base.tmpl @@ -0,0 +1,2 @@ +this is base.html +Hello world! \ No newline at end of file diff --git a/templates/home.tmpl b/templates/home.tmpl new file mode 100644 index 0000000000..0c98a69766 --- /dev/null +++ b/templates/home.tmpl @@ -0,0 +1 @@ +{{template "base/base"}} \ No newline at end of file diff --git a/utils/conf.go b/utils/conf.go new file mode 100644 index 0000000000..0b1a39908d --- /dev/null +++ b/utils/conf.go @@ -0,0 +1,24 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package utils + +import ( + "fmt" + "os" + + "github.com/Unknwon/goconfig" +) + +var Cfg *goconfig.ConfigFile + +func init() { + var err error + Cfg, err = goconfig.LoadConfigFile("conf/app.ini") + if err != nil { + fmt.Println("Cannot load config file 'app.ini'") + os.Exit(2) + } + Cfg.BlockMode = false +} diff --git a/utils/log/log.go b/utils/log/log.go new file mode 100644 index 0000000000..c725c5276e --- /dev/null +++ b/utils/log/log.go @@ -0,0 +1,21 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Package log is a wrapper of logs for short calling name. +package log + +import ( + "github.com/gogits/logs" +) + +var logger *logs.BeeLogger + +func init() { + logger = logs.NewLogger(10000) + logger.SetLogger("console", "") +} + +func Info(format string, v ...interface{}) { + logger.Info(format, v...) +}