Skip to content

Commit

Permalink
fix: format code using gofumpt tool (gin-gonic#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored Sep 3, 2022
1 parent 9f71446 commit 938fbf5
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 57 deletions.
9 changes: 6 additions & 3 deletions assets-in-binary/example01/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"github.com/jessevdk/go-assets"
)

var _Assetsbfa8d115ce0617d89507412d5393a462f8e9b003 = "<!doctype html>\n<body>\n <p>Can you see this? → {{.Bar}}</p>\n</body>\n"
var _Assets3737a75b5254ed1f6d588b40a3449721f9ea86c2 = "<!doctype html>\n<body>\n <p>Hello, {{.Foo}}</p>\n</body>\n"
var (
_Assetsbfa8d115ce0617d89507412d5393a462f8e9b003 = "<!doctype html>\n<body>\n <p>Can you see this? → {{.Bar}}</p>\n</body>\n"
_Assets3737a75b5254ed1f6d588b40a3449721f9ea86c2 = "<!doctype html>\n<body>\n <p>Hello, {{.Foo}}</p>\n</body>\n"
)

// Assets returns go-assets FileSystem
var Assets = assets.NewFileSystem(map[string][]string{"/": {"html"}, "/html": {"bar.tmpl", "index.tmpl"}}, map[string]*assets.File{
Expand All @@ -31,4 +33,5 @@ var Assets = assets.NewFileSystem(map[string][]string{"/": {"html"}, "/html": {"
FileMode: 0x1a4,
Mtime: time.Unix(1524365491, 1524365491289995821),
Data: []byte(_Assets3737a75b5254ed1f6d588b40a3449721f9ea86c2),
}}, "")
},
}, "")
1 change: 0 additions & 1 deletion assets-in-binary/example02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
var f embed.FS

func main() {

router := gin.Default()
templ := template.Must(template.New("").ParseFS(f, "templates/*.tmpl", "templates/foo/*.tmpl"))
router.SetHTMLTemplate(templ)
Expand Down
1 change: 1 addition & 0 deletions graceful-shutdown/close/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.8
// +build go1.8

package main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.8
// +build go1.8

package main
Expand Down
4 changes: 1 addition & 3 deletions group-routes/routes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"github.com/gin-gonic/gin"
)

var (
router = gin.Default()
)
var router = gin.Default()

// Run will start the server
func Run() {
Expand Down
4 changes: 1 addition & 3 deletions multiple-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"golang.org/x/sync/errgroup"
)

var (
g errgroup.Group
)
var g errgroup.Group

func router01() http.Handler {
e := gin.New()
Expand Down
1 change: 0 additions & 1 deletion realtime-advanced/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func roomGET(c *gin.Context) {
"nick": nick,
"timestamp": time.Now().Unix(),
})

}

func roomPOST(c *gin.Context) {
Expand Down
46 changes: 23 additions & 23 deletions realtime-chat/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import (
type Message struct {
UserId string
RoomId string
Text string
Text string
}

type Listener struct {
RoomId string
Chan chan interface{}
Chan chan interface{}
}

type Manager struct {
roomChannels map[string]broadcast.Broadcaster
open chan *Listener
close chan *Listener
delete chan string
messages chan *Message
open chan *Listener
close chan *Listener
delete chan string
messages chan *Message
}

func NewRoomManager() *Manager {
manager := &Manager{
roomChannels: make(map[string]broadcast.Broadcaster),
open: make(chan *Listener, 100),
close: make(chan *Listener, 100),
delete: make(chan string, 100),
messages: make(chan *Message, 100),
open: make(chan *Listener, 100),
close: make(chan *Listener, 100),
delete: make(chan string, 100),
messages: make(chan *Message, 100),
}

go manager.run()
Expand All @@ -39,14 +39,14 @@ func NewRoomManager() *Manager {
func (m *Manager) run() {
for {
select {
case listener := <- m.open:
m.register(listener)
case listener := <- m.close:
m.deregister(listener)
case roomid := <- m.delete:
m.deleteBroadcast(roomid)
case message := <- m.messages:
m.room(message.RoomId).Submit(message.UserId + ": " + message.Text)
case listener := <-m.open:
m.register(listener)
case listener := <-m.close:
m.deregister(listener)
case roomid := <-m.delete:
m.deleteBroadcast(roomid)
case message := <-m.messages:
m.room(message.RoomId).Submit(message.UserId + ": " + message.Text)
}
}
}
Expand Down Expand Up @@ -77,31 +77,31 @@ func (m *Manager) room(roomid string) broadcast.Broadcaster {
return b
}

func (m *Manager) OpenListener(roomid string) chan interface{}{
func (m *Manager) OpenListener(roomid string) chan interface{} {
listener := make(chan interface{})
m.open <- &Listener{
RoomId: roomid,
Chan: listener,
Chan: listener,
}
return listener
}

func (m *Manager) CloseListener(roomid string, channel chan interface{}) {
m.close <- &Listener{
RoomId: roomid,
Chan: channel,
Chan: channel,
}
}

func (m *Manager) DeleteBroadcast(roomid string) {
m.delete <- roomid
}

func (m *Manager) Submit (userid, roomid, text string) {
func (m *Manager) Submit(userid, roomid, text string) {
msg := &Message{
UserId: userid,
RoomId: roomid,
Text: text,
Text: text,
}
m.messages <- msg
}
10 changes: 4 additions & 6 deletions reverse-proxy/reverseServer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ const (
ReverseServerAddr = "127.0.0.1:2002"
)

var (
// maybe we can have many real server addresses and do some load balanced strategy.
RealAddr = []string{
"http://127.0.0.1:2003",
}
)
// maybe we can have many real server addresses and do some load balanced strategy.
var RealAddr = []string{
"http://127.0.0.1:2003",
}

// a fake function that we can do strategy here.
func getLoadBalanceAddr() string {
Expand Down
11 changes: 6 additions & 5 deletions send_chunked_data/send_chunked_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package main

import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"

"github.com/gin-gonic/gin"
)

func main(){
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
r := gin.Default()
r.GET("/test_stream", func(c *gin.Context){
r.GET("/test_stream", func(c *gin.Context) {
w := c.Writer
header := w.Header()
header.Set("Transfer-Encoding", "chunked")
Expand All @@ -22,10 +23,10 @@ func main(){
<body>
`))
w.(http.Flusher).Flush()
for i:=0 ;i<10; i++{
for i := 0; i < 10; i++ {
w.Write([]byte(fmt.Sprintf(`
<h1>%d</h1>
`,i)))
`, i)))
w.(http.Flusher).Flush()
time.Sleep(time.Duration(1) * time.Second)
}
Expand Down
3 changes: 1 addition & 2 deletions server-sent-event/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ func main() {
})
})

//Parse Static files
// Parse Static files
router.StaticFile("/", "./public/index.html")

router.Run(":8085")
}

// Initialize event and Start procnteessing requests
func NewServer() (event *Event) {

event = &Event{
Message: make(chan string),
NewClients: make(chan chan string),
Expand Down
2 changes: 1 addition & 1 deletion struct-lvl-validations/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type User struct {
// hooks right into validator and you can combine with validation tags and still have a
// common error output format.
func UserStructLevelValidation(sl validator.StructLevel) {
//user := structLevel.CurrentStruct.Interface().(User)
// user := structLevel.CurrentStruct.Interface().(User)
user := sl.Current().Interface().(User)

if len(user.FirstName) == 0 && len(user.LastName) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {

router.GET("/raw", func(c *gin.Context) {
c.HTML(http.StatusOK, "raw.tmpl", gin.H{
"now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
"now": time.Date(2017, 0o7, 0o1, 0, 0, 0, 0, time.UTC),
})
})

Expand Down
11 changes: 3 additions & 8 deletions versioning/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"github.com/gin-gonic/gin"
"net/http"

"github.com/gin-gonic/gin"
)

func main() {

router := gin.Default()

// version 1
Expand All @@ -21,7 +21,7 @@ func main() {

authV1.POST("users/add", AddV1User)

//version 2
// version 2
apiV2 := router.Group("/v2")

apiV2.GET("users", func(c *gin.Context) {
Expand All @@ -34,26 +34,22 @@ func main() {
authV2.POST("users/add", AddV2User)

_ = router.Run(":8081")

}

func AddV1User(c *gin.Context) {

// AddUser

c.JSON(http.StatusOK, "V1 User added")
}

func AddV2User(c *gin.Context) {

// AddUser

c.JSON(http.StatusOK, "V2 User added")
}

func AuthMiddleWare() gin.HandlerFunc {
return func(c *gin.Context) {

// here you can add your authentication method to authorize users.
username := c.PostForm("user")
password := c.PostForm("password")
Expand All @@ -63,6 +59,5 @@ func AuthMiddleWare() gin.HandlerFunc {
} else {
c.AbortWithStatus(http.StatusUnauthorized)
}

}
}

0 comments on commit 938fbf5

Please sign in to comment.