Skip to content

Commit f1d13ee

Browse files
committed
init
1 parent 1146178 commit f1d13ee

File tree

10 files changed

+5647
-3
lines changed

10 files changed

+5647
-3
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
tgw
2-
===
1+
# Tiny Go Web
2+
3+
Tiny Go Web (TGW)是一个非常简单的Web框架,甚至谈不上框架。TGW无意取代任何框架,TGW的诞生是因为作者在使用beego时有种挫败感,决定自己重新写一个适合自己网站用的,从构思到完成总共
4+
只花了一天的时间,因为觉得它已经够用了,就没有继续添加新的功能。
5+
6+
TGW使用非常简单,没有固定的目录结构,不过遵循大众习惯,我把它组成以下结构:
7+
8+
│── controllers
9+
│   ├── default.go
10+
├── main.go
11+
├── models
12+
│   └── book.go
13+
├── static
14+
│   ├── css
15+
│   ├── img
16+
│   └── js
17+
└──── view
18+
   ├── include
19+
   │   └── nav.html
20+
   └── index.html
21+
22+
323

4-
Tiny Go Web

example/controllers/default.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package controllers
2+
3+
import (
4+
"github.com/icattlecoder/tgw"
5+
. "github.com/icattlecoder/tgw/example/models"
6+
)
7+
8+
type Server struct {
9+
//
10+
}
11+
12+
func NewServer( /**/) *Server {
13+
return &Server{}
14+
}
15+
16+
type TestArgs struct {
17+
Msg string
18+
}
19+
20+
func (s *Server) Hello(args TestArgs, env tgw.ReqEnv) {
21+
env.RW.Write([]byte(args.Msg))
22+
}
23+
24+
func (s *Server) Index() (data map[string]interface{}) {
25+
data = map[string]interface{}{}
26+
author := Author{
27+
Name: "icattlecoder",
28+
Email: []string{"[email protected]", "[email protected]"},
29+
QQ: "405283013",
30+
Blog: "http://blog.segmentfault.com/icattlecoder",
31+
}
32+
data["author"] = author
33+
return
34+
}
35+
36+
func (s *Server) Json() (data map[string]interface{}) {
37+
data = map[string]interface{}{}
38+
author := Author{
39+
Name: "icattlecoder",
40+
Email: []string{"[email protected]", "[email protected]"},
41+
QQ: "405283013",
42+
Blog: "http://blog.segmentfault.com/icattlecoder",
43+
}
44+
data["author"] = author
45+
return
46+
}

example/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"github.com/icattlecoder/tgw"
5+
"github.com/icattlecoder/tgw/example/controllers"
6+
"log"
7+
"net/http"
8+
)
9+
10+
func main() {
11+
ser := controllers.NewServer()
12+
mux := tgw.Register(&ser)
13+
log.Fatal(http.ListenAndServe(":8080", mux))
14+
15+
}

example/models/author.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package models
2+
3+
type Author struct {
4+
Name string
5+
Email []string
6+
QQ string
7+
Blog string
8+
}

0 commit comments

Comments
 (0)