Skip to content

Commit 0d61fc7

Browse files
author
lisensen
committed
change page of go mdo
1 parent de8187d commit 0d61fc7

20 files changed

+194
-137
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<a href="https://www.zhihu.com/people/sencoed.com/activities"><img src="https://img.shields.io/badge/%E7%9F%A5%E4%B9%8E-keke-green.svg?style=flat&colorA=009df2"></a>
1010
</p>
1111

12-
`spike`项目用的是`Golang 1.11.2`版本,本项目采用了go module,配合Golang的web框架gin实现的.
12+
`spike`项目用的是`Golang 1.13 `版本,本项目采用了go module,配合Golang的web框架gin实现的.
1313

1414
#### Docker
1515
```docker
@@ -123,6 +123,35 @@ docker中,go构建命令使用 `-ldflags="-s -w"`,在官方文档:Command_Line
123123

124124
多阶段镜像构建可以让开发者通过一个Dockerfile,一次性地、更容易地构建出size较小的image,体验良好并且更容易接入CI/CD等自动化系统。
125125

126+
此外我们如果有私有仓库或者需要加代理请求的一些依赖包的时候需要配置下:
127+
```markdown
128+
export GO111MODULE=on
129+
export GOPROXY=https://goproxy.io,https://goproxy.cn,direct
130+
export GOPRIVATE=*.private.com
131+
```
132+
133+
```markdown
134+
> vim .gitconfig
135+
136+
1 [core]
137+
2 excludesfile = /Users/admin/.gitignore_global
138+
3 [difftool "sourcetree"]
139+
4 cmd = opendiff \"$LOCAL\" \"$REMOTE\"
140+
5 path =
141+
6 [mergetool "sourcetree"]
142+
7 cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
143+
8 trustExitCode = true
144+
9 [user]
145+
10 name = keke
146+
11 email = [email protected]
147+
12 [url "[email protected]:"]
148+
13 insteadOf = https://gitlab.private.com/
149+
14 [commit]
150+
15 template = /Users/admin/.stCommitMsg
151+
152+
```
153+
这样配置之后,获取和更新项目配置就很容易了.
154+
126155
#### Golang编程
127156

128157
觉得此文章不错,支持我的话可以给我star ,:star:!如果有问题可以加我的微信`Sen0676`,也可以加入我们的交流群一起交流goalng技术!

config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
type ApplicationConfig struct {
11-
ENV string
12-
Port string
13-
DB *gorm.DB
14-
Render *render.Render
15-
Mysql *configurations.Mysql
16-
Sqlite string
11+
ENV string
12+
Port string
13+
DB *gorm.DB
14+
Render *render.Render
15+
Mysql *configurations.Mysql
16+
Sqlite string
1717
}

controllers/application_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package controllers
22

33
import (
4-
"fmt"
54
"encoding/json"
5+
"fmt"
66

77
"spike/config"
88

controllers/authority_controller.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package controllers
22

33
import (
4-
"net/http"
5-
"io/ioutil"
64
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
77

88
redis_authories "spike/helps/redis"
99

10-
"github.com/unrolled/render"
1110
"github.com/gin-gonic/gin"
12-
11+
"github.com/unrolled/render"
1312
)
1413

1514
type AuthorityController struct {
@@ -20,15 +19,15 @@ const (
2019
AuthorityKey = "ALLIANCE::AUTHORITY"
2120
)
2221

23-
func (ctrl AuthorityController)New(c *gin.Context) {
22+
func (ctrl AuthorityController) New(c *gin.Context) {
2423
ctrl.Render.HTML(c.Writer, http.StatusOK, "authority/index", nil, render.HTMLOptions{Layout: "authority/templates"})
2524
}
2625

27-
func (ctrl AuthorityController)All(c *gin.Context) {
26+
func (ctrl AuthorityController) All(c *gin.Context) {
2827
resp := ctrl.NewResponse()
29-
allianceRedis := redis_authories.Alliance{Redis:ctrl.RedisPool, Key:AuthorityKey}
28+
allianceRedis := redis_authories.Alliance{Redis: ctrl.RedisPool, Key: AuthorityKey}
3029
authories := make([]redis_authories.Authority, 0)
31-
s:=allianceRedis.GetAll()
30+
s := allianceRedis.GetAll()
3231
err := json.Unmarshal([]byte(s), &authories)
3332
if err != nil {
3433
resp.ErrorCode = 1
@@ -59,7 +58,7 @@ func (ctrl AuthorityController) Save(c *gin.Context) {
5958
c.JSON(http.StatusOK, resp)
6059
return
6160
}
62-
allianceRedis := redis_authories.Alliance{Redis:ctrl.RedisPool, Key:AuthorityKey}
61+
allianceRedis := redis_authories.Alliance{Redis: ctrl.RedisPool, Key: AuthorityKey}
6362
err = allianceRedis.Save(string(data))
6463
if err != nil {
6564
resp.ErrorCode = 1
@@ -70,4 +69,4 @@ func (ctrl AuthorityController) Save(c *gin.Context) {
7069
resp.ErrorCode = 0
7170
resp.Data = authories
7271
c.JSON(http.StatusOK, resp)
73-
}
72+
}

controllers/gpg_keys_controller.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (ctrl GpgKeysController) Show(c *gin.Context) {
4040

4141
func (ctrl GpgKeysController) Detail(c *gin.Context) {
4242
id, _ := strconv.ParseUint(c.Param("id"), 10, 0)
43-
gpgKey := models.GpgKey{ID:uint(id)}
43+
gpgKey := models.GpgKey{ID: uint(id)}
4444
err := ctrl.DB.First(&gpgKey).Error
4545
if err != nil {
4646
ctrl.Render.Text(c.Writer, http.StatusOK, err.Error())
@@ -70,10 +70,8 @@ func (ctrl GpgKeysController) New(c *gin.Context) {
7070

7171
func (ctrl GpgKeysController) Create(c *gin.Context) {
7272

73-
7473
}
7574

76-
7775
func (ctrl GpgKeysController) Edit(c *gin.Context) {
7876

7977
id, err := strconv.ParseUint(c.Param("id"), 10, 0)
@@ -98,14 +96,14 @@ func (ctrl GpgKeysController) Update(c *gin.Context) {
9896
resp := ctrl.NewResponse()
9997

10098
armor, err := strconv.ParseBool(c.PostForm("armor"))
101-
if err !=nil{
99+
if err != nil {
102100
ctrl.Render.Text(c.Writer, http.StatusOK, err.Error())
103101
return
104102
}
105103
comment := c.PostForm("comment")
106104
email := c.PostForm("email")
107105
id, err := strconv.ParseUint(c.Param("id"), 10, 0)
108-
if err != nil{
106+
if err != nil {
109107
ctrl.Render.Text(c.Writer, http.StatusOK, err.Error())
110108
return
111109
}
@@ -168,4 +166,3 @@ func (ctrl GpgKeysController) Delete(c *gin.Context) {
168166
ctrl.Render.JSON(c.Writer, http.StatusOK, resp)
169167
}
170168
}
171-

controllers/news_controller.go

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package controllers
22

33
import (
44
"fmt"
5-
"strconv"
65
"net/http"
6+
"strconv"
77

8-
"spike/models"
98
"spike/helps/sql"
9+
"spike/models"
1010

1111
"github.com/gin-gonic/gin"
1212
)
@@ -87,97 +87,95 @@ func (ctrl NewsController) List(c *gin.Context) {
8787
Data interface{} `json:"data"`
8888
PageInfo interface{} `json:"page_info"`
8989
}{
90-
Data:n,
91-
PageInfo:pagination,
90+
Data: n,
91+
PageInfo: pagination,
9292
}
9393

9494
resp.ErrorCode = 0
9595
resp.Data = result
96-
c.JSON(http.StatusOK,resp)
96+
c.JSON(http.StatusOK, resp)
9797

9898
}
9999

100-
func (ctrl NewsController) Show(c *gin.Context){
101-
100+
func (ctrl NewsController) Show(c *gin.Context) {
102101

103102
}
104103

105-
106-
func (ctrl NewsController) Publish(c *gin.Context){
104+
func (ctrl NewsController) Publish(c *gin.Context) {
107105
resp := ctrl.NewResponse()
108106

109-
id ,err := strconv.ParseUint(c.Param("id"),10,64)
110-
if err != nil{
107+
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
108+
if err != nil {
111109
resp.ErrorMessage = err.Error()
112-
c.JSON(http.StatusOK,resp)
110+
c.JSON(http.StatusOK, resp)
113111
return
114112
}
115113

116-
req := &struct {ID uint64}{ID:id}
114+
req := &struct{ ID uint64 }{ID: id}
117115
n := &models.News{}
118-
err = ctrl.DB.Model(n).First(n,req.ID).Error
119-
if err != nil{
116+
err = ctrl.DB.Model(n).First(n, req.ID).Error
117+
if err != nil {
120118
resp.ErrorMessage = err.Error()
121-
c.JSON(http.StatusOK,resp)
119+
c.JSON(http.StatusOK, resp)
122120
return
123121
}
124122

125-
if n.State == int(models.Pendding){
123+
if n.State == int(models.Pendding) {
126124
resp.ErrorMessage = "news state is pendding"
127-
c.JSON(http.StatusOK,resp)
125+
c.JSON(http.StatusOK, resp)
128126
return
129127
}
130128

131-
err = ctrl.DB.Model(&models.News{}).Where("id=?",req.ID).Update("state",models.Pushlish).Error
132-
if err != nil{
129+
err = ctrl.DB.Model(&models.News{}).Where("id=?", req.ID).Update("state", models.Pushlish).Error
130+
if err != nil {
133131
resp.ErrorMessage = err.Error()
134-
c.JSON(http.StatusOK,resp)
132+
c.JSON(http.StatusOK, resp)
135133
return
136134
}
137135
resp.ErrorCode = 0
138-
c.JSON(http.StatusOK,resp)
136+
c.JSON(http.StatusOK, resp)
139137
}
140138

141-
func (ctrl NewsController) Offline(c *gin.Context){
139+
func (ctrl NewsController) Offline(c *gin.Context) {
142140
resp := ctrl.NewResponse()
143141

144-
id,err := strconv.ParseUint(c.Param("id"),10,64)
145-
if err != nil{
142+
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
143+
if err != nil {
146144
resp.ErrorMessage = err.Error()
147-
c.JSON(http.StatusOK,resp)
145+
c.JSON(http.StatusOK, resp)
148146
return
149147
}
150148

151-
req := &struct {ID uint64}{ID:id}
149+
req := &struct{ ID uint64 }{ID: id}
152150

153151
n := &models.News{}
154152

155-
err = ctrl.DB.Model(n).First(n,req.ID).Error
156-
if err != nil{
153+
err = ctrl.DB.Model(n).First(n, req.ID).Error
154+
if err != nil {
157155
resp.ErrorMessage = err.Error()
158-
c.JSON(http.StatusOK,resp)
156+
c.JSON(http.StatusOK, resp)
159157
return
160158
}
161159

162-
if n.State == int(models.Pushlish){
160+
if n.State == int(models.Pushlish) {
163161
resp.ErrorMessage = "news state is publish"
164-
c.JSON(http.StatusOK,resp)
162+
c.JSON(http.StatusOK, resp)
165163
return
166164
}
167165

168-
err = ctrl.DB.Model(&models.News{}).Where("id=? AND state=?",req.ID,models.Pushlish).
169-
Update("state",models.OffLine).Error
170-
if err != nil{
166+
err = ctrl.DB.Model(&models.News{}).Where("id=? AND state=?", req.ID, models.Pushlish).
167+
Update("state", models.OffLine).Error
168+
if err != nil {
171169
resp.ErrorMessage = err.Error()
172-
c.JSON(http.StatusOK,resp)
170+
c.JSON(http.StatusOK, resp)
173171
return
174172
}
175173

176174
resp.ErrorCode = 0
177-
c.JSON(http.StatusOK,resp)
175+
c.JSON(http.StatusOK, resp)
178176
}
179177

180-
func (ctrl NewsController) Create(c *gin.Context){
178+
func (ctrl NewsController) Create(c *gin.Context) {
181179
resp := ctrl.NewResponse()
182180

183181
title := c.PostForm("title")
@@ -187,26 +185,24 @@ func (ctrl NewsController) Create(c *gin.Context){
187185
author := c.PostForm("author")
188186
imageUrl := c.PostForm("imageUrl")
189187

190-
191188
news := models.News{
192-
Title: title,
193-
Summary:summary,
194-
Body:body,
195-
Code:code,
196-
Author:author,
197-
ImageUrl:imageUrl,
189+
Title: title,
190+
Summary: summary,
191+
Body: body,
192+
Code: code,
193+
Author: author,
194+
ImageUrl: imageUrl,
198195
}
199196

200197
err := ctrl.DB.Create(&news).Error
201-
if err != nil{
198+
if err != nil {
202199
resp.ErrorCode = 1
203200
resp.ErrorMessage = err.Error()
204-
c.JSON(http.StatusOK,resp)
201+
c.JSON(http.StatusOK, resp)
205202
return
206203
}
207204

208205
resp.ErrorCode = 0
209-
c.JSON(http.StatusOK,resp)
210-
206+
c.JSON(http.StatusOK, resp)
211207

212-
}
208+
}

controllers/user_controller.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func (ctrl UserController) Index(c *gin.Context) {
1616
var users []models.User
1717

1818
err := ctrl.DB.Model(&models.User{}).Find(&users).Error
19-
if err != nil{
19+
if err != nil {
2020
resp.ErrorCode = 1
2121
resp.ErrorMessage = err.Error()
22-
c.JSON(http.StatusOK,resp)
22+
c.JSON(http.StatusOK, resp)
2323
return
2424
}
2525
resp.ErrorCode = 0
26-
c.JSON(http.StatusOK,resp)
26+
c.JSON(http.StatusOK, resp)
2727
return
2828
}
2929

@@ -34,20 +34,19 @@ func (ctrl UserController) Create(c *gin.Context) {
3434
email := c.PostForm("email")
3535
encryptedPassword := c.PostForm("encryptedPassword")
3636

37-
3837
user := models.User{
39-
Name: name,
40-
Email:email,
41-
EncryptedPassword:encryptedPassword,
38+
Name: name,
39+
Email: email,
40+
EncryptedPassword: encryptedPassword,
4241
}
4342

4443
err := ctrl.DB.Model(&user).Error
45-
if err != nil{
44+
if err != nil {
4645
resp.ErrorCode = 1
4746
resp.ErrorMessage = err.Error()
48-
c.JSON(http.StatusOK,resp)
47+
c.JSON(http.StatusOK, resp)
4948
return
5049
}
5150
resp.ErrorCode = 0
52-
c.JSON(http.StatusOK,resp)
51+
c.JSON(http.StatusOK, resp)
5352
}

0 commit comments

Comments
 (0)