├── tmp └── .gitkeep ├── public ├── js │ └── .gitkeep ├── robots.txt ├── images │ └── favicon.ico └── css │ └── style.css ├── controllers ├── api.go └── main.go ├── helpers ├── template.go └── auth.go ├── config.toml.example ├── .gitignore ├── system ├── configuration.go ├── gzip.go ├── controller.go ├── core.go └── middleware.go ├── views ├── footer.html ├── home.html ├── header.html ├── auth │ ├── signin.html │ └── signup.html └── main.html ├── README.md ├── LICENSE ├── server.go └── models └── user.go /tmp/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/js/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # hello robots 2 | 3 | User-agent: * 4 | Disallow: /logout/ 5 | 6 | -------------------------------------------------------------------------------- /public/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haruyama/golang-goji-sample/HEAD/public/images/favicon.ico -------------------------------------------------------------------------------- /controllers/api.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "github.com/haruyama/golang-goji-sample/system" 5 | ) 6 | 7 | type ApiController struct { 8 | system.Controller 9 | } 10 | -------------------------------------------------------------------------------- /helpers/template.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "html/template" 5 | "bytes" 6 | ) 7 | 8 | func Parse(t *template.Template, name string, data interface{}) string { 9 | var doc bytes.Buffer 10 | t.ExecuteTemplate(&doc, name, data) 11 | return doc.String() 12 | } 13 | 14 | -------------------------------------------------------------------------------- /config.toml.example: -------------------------------------------------------------------------------- 1 | [general] 2 | public_path = "public" 3 | template_path = "views" 4 | 5 | [cookie] 6 | mac_secret = "secret string which has over 256-bit entropy" 7 | secure = false 8 | 9 | [database] 10 | user = "root" 11 | password = "" 12 | hostname = "localhost" 13 | port = "3306" 14 | database = "goji" 15 | 16 | [csrf] 17 | key = "csrf_token" 18 | cookie = "XSRF-TOKEN" 19 | header = "X-XSRF-TOKEN" 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | 25 | /config.toml 26 | *~ 27 | .*.swp 28 | tmp/* 29 | golang-goji-sample 30 | -------------------------------------------------------------------------------- /system/configuration.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | type ConfigurationDatabase struct { 4 | User string `json:"user"` 5 | Password string `json:"password"` 6 | Hostname string `json:"hostname"` 7 | Database string `json:"database"` 8 | } 9 | 10 | type Configuration struct { 11 | Secret string `json:"secret"` 12 | PublicPath string `json:"public_path"` 13 | TemplatePath string `json:"template_path"` 14 | Database ConfigurationDatabase 15 | } 16 | -------------------------------------------------------------------------------- /helpers/auth.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "golang.org/x/crypto/bcrypt" 5 | "gopkg.in/gorp.v1" 6 | "github.com/haruyama/golang-goji-sample/models" 7 | ) 8 | 9 | func Login(dbMap *gorp.DbMap, email string, password string) (*models.User, error) { 10 | var user models.User 11 | err := dbMap.SelectOne(&user, "SELECT * FROM Users WHERE Email = ?", email) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | err = bcrypt.CompareHashAndPassword(user.Password, []byte(password)) 17 | if err != nil { 18 | return nil, err 19 | } 20 | return &user, err 21 | } 22 | -------------------------------------------------------------------------------- /views/footer.html: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |