Skip to content

Commit 693bb12

Browse files
author
lisensen
committed
change page of readme
0 parents  commit 693bb12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+23239
-0
lines changed

.env

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
TZ=Asia/Shanghai
2+
3+
APP_ENV=local
4+
APP_DEBUG=false
5+
APP_TIMEZONE=Asia/Shanghai
6+
7+
DB_CONNECTION=mysql
8+
9+
10+
MYSQL_ROOT_PASSWORD=admin123
11+
MYSQL_INITDB_SKIP_TZINFO=true
12+
MYSQL_HOSTNAME=mysql
13+
MYSQL_PORT=3306
14+
MYSQL_DATABASE=spike
15+
MYSQL_USER=spike
16+
MYSQL_PASSWORD=admin123
17+
MYSQL_TIMEZONE=+08:00
18+
19+
20+
CACHE_DRIVER=file
21+
QUEUE_DRIVER=sync
22+

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.idea
2+
/test
3+
gin-bin
4+
spike.iml
5+
app.conf
6+
app.pid
7+
glide.yaml
8+
spike
9+
file.zip
10+
sqlite
11+
spike.tar.gz

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#母镜像
2+
FROM golang:latest
3+
#维护者信息
4+
MAINTAINER keke
5+
#工作目录
6+
WORKDIR $GOPATH/src/go
7+
#将文件复制到镜像中
8+
ADD . $GOPATH/src/go
9+
#执行操作
10+
RUN go build main.go
11+
#暴露端口
12+
EXPOSE 8080
13+
#程序入口
14+
ENTRYPOINT ["./main"]

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# spike
2+
用的是Golang 1.112版本的go module实现的.
3+
4+
#### docker
5+
6+
```markdown
7+
#母镜像
8+
FROM golang
9+
#维护者信息
10+
MAINTAINER keke
11+
#工作目录
12+
WORKDIR $GOPATH/src/go
13+
#将文件复制到镜像中
14+
ADD . $GOPATH/src/go
15+
#执行操作
16+
RUN go build main.go
17+
#暴露端口
18+
EXPOSE 8080
19+
#程序入口
20+
ENTRYPOINT ["./main"]
21+
```
22+
23+
然后运行下面的命令把当前编译过项目打进docker镜像:
24+
25+
```bash
26+
> docker build -t main.go .
27+
28+
---> 797daa9977c6
29+
Successfully built 797daa9977c6
30+
Successfully tagged main.go:latest
31+
```
32+
33+
```bash
34+
> docker images
35+
main.go latest 797daa9977c6 8 minutes ago 801MB
36+
```
37+
38+
表示把项目成功打进docker镜像了.
39+
40+
```bash
41+
> docker run -p 8080:8080 -d main.go
42+
```
43+
44+
docker run -p 80:8080 oracle:latest 可以直接docker运行本地镜像启动go项目

app.conf.sample

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
ENV = "debug"
3+
Port = "8000"
4+
Sqlite = "sqlite"
5+
6+
[Mysql]
7+
Type = ""
8+
UserName = "root"
9+
Password = "hadoop"
10+
Database = "spike"
11+
Address = ""
12+
Parameters = "charset=utf8&parseTime=True&loc=Local"
13+
MaxIdle = 10
14+
MaxOpen = 100
15+
Debug = true
16+
MigrationsDir = "/path/to/db/migrations"
17+

config/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package config
2+
3+
import (
4+
"spike/helps/configurations"
5+
6+
"github.com/jinzhu/gorm"
7+
"github.com/unrolled/render"
8+
)
9+
10+
type ApplicationConfig struct {
11+
ENV string
12+
Port string
13+
DB *gorm.DB
14+
Render *render.Render
15+
Mysql *configurations.Mysql
16+
Sqlite string
17+
}

controllers/application_controller.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"encoding/json"
6+
7+
"spike/config"
8+
9+
"github.com/garyburd/redigo/redis"
10+
"github.com/jinzhu/gorm"
11+
"github.com/unrolled/render"
12+
)
13+
14+
type ApplicationController struct {
15+
RedisPool *redis.Pool
16+
DB *gorm.DB
17+
Render *render.Render
18+
Config *config.ApplicationConfig
19+
}
20+
21+
func (a ApplicationController) Log(v ...interface{}) {
22+
fmt.Println(v)
23+
}
24+
25+
type ApiResponse struct {
26+
ErrorCode int `json:"error_code"`
27+
ErrorMessage string `json:"error_message"`
28+
Data interface{} `json:"response,omitempty"`
29+
}
30+
31+
func (act ApplicationController) NewResponse() *ApiResponse {
32+
return &ApiResponse{}
33+
}
34+
35+
func (a *ApiResponse) ToJSON() []byte {
36+
result, _ := json.Marshal(a)
37+
return result
38+
}

controllers/authority_controller.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package controllers
2+
3+
import (
4+
"net/http"
5+
"io/ioutil"
6+
"encoding/json"
7+
8+
redis_authories "spike/helps/redis"
9+
10+
"github.com/unrolled/render"
11+
"github.com/gin-gonic/gin"
12+
13+
)
14+
15+
type AuthorityController struct {
16+
ApplicationController
17+
}
18+
19+
const (
20+
AuthorityKey = "ALLIANCE::AUTHORITY"
21+
)
22+
23+
func (ctrl AuthorityController)New(c *gin.Context) {
24+
ctrl.Render.HTML(c.Writer, http.StatusOK, "authority/index", nil, render.HTMLOptions{Layout: "authority/templates"})
25+
}
26+
27+
func (ctrl AuthorityController)All(c *gin.Context) {
28+
resp := ctrl.NewResponse()
29+
allianceRedis := redis_authories.Alliance{Redis:ctrl.RedisPool, Key:AuthorityKey}
30+
authories := make([]redis_authories.Authority, 0)
31+
s:=allianceRedis.GetAll()
32+
err := json.Unmarshal([]byte(s), &authories)
33+
if err != nil {
34+
resp.ErrorCode = 1
35+
resp.ErrorMessage = err.Error()
36+
c.JSON(http.StatusOK, resp)
37+
return
38+
}
39+
resp.ErrorCode = 0
40+
resp.Data = authories
41+
c.JSON(http.StatusOK, resp)
42+
}
43+
44+
func (ctrl AuthorityController) Save(c *gin.Context) {
45+
resp := ctrl.NewResponse()
46+
data, err := ioutil.ReadAll(ioutil.NopCloser(c.Request.Body))
47+
if err != nil {
48+
resp.ErrorCode = 1
49+
resp.ErrorMessage = "参数解析错误"
50+
c.JSON(http.StatusOK, resp)
51+
return
52+
}
53+
defer c.Request.Body.Close()
54+
authories := make([]redis_authories.Authority, 0)
55+
err = json.Unmarshal(data, &authories)
56+
if err != nil {
57+
resp.ErrorCode = 1
58+
resp.ErrorMessage = err.Error()
59+
c.JSON(http.StatusOK, resp)
60+
return
61+
}
62+
allianceRedis := redis_authories.Alliance{Redis:ctrl.RedisPool, Key:AuthorityKey}
63+
err = allianceRedis.Save(string(data))
64+
if err != nil {
65+
resp.ErrorCode = 1
66+
resp.ErrorMessage = err.Error()
67+
c.JSON(http.StatusOK, resp)
68+
return
69+
}
70+
resp.ErrorCode = 0
71+
resp.Data = authories
72+
c.JSON(http.StatusOK, resp)
73+
}

0 commit comments

Comments
 (0)