From 96b317d3fff3884dd08061d84e11a49495f83a4b Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 12 Feb 2014 14:54:09 -0500 Subject: [PATCH] Init commit --- .gitignore | 1 + conf/app.ini | 6 +++++- gogs.go | 30 ++++++++++++++++++++++++++---- routers/home.go | 8 ++++++-- templates/base/base.tmpl | 2 ++ templates/home.tmpl | 1 + utils/conf.go | 24 ++++++++++++++++++++++++ utils/log/log.go | 21 +++++++++++++++++++++ 8 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 templates/base/base.tmpl create mode 100644 templates/home.tmpl create mode 100644 utils/conf.go create mode 100644 utils/log/log.go diff --git a/.gitignore b/.gitignore index 82a084b50..92b579f22 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 f70745d28..9d56816bb 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 8a4b9e000..c0b11fb86 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 5bb12f6dd..ec7077d80 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 000000000..2a28b7911 --- /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 000000000..0c98a6976 --- /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 000000000..0b1a39908 --- /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 000000000..c725c5276 --- /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...) +}