-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consolidate code examples into new file
- Remove an unnecessary line in the README.md file - Add a new file `_example/example03/main.go` - Add the same code to `_example/example03/main.go` as in the README.md file - Update the `_example/example01/main.go` and `_example/example02/main.go` files to match the changes in the README.md file Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
4 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
ginzap "github.com/gin-contrib/zap" | ||
|
||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func main() { | ||
r := gin.New() | ||
|
||
logger, _ := zap.NewProduction() | ||
|
||
r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{ | ||
UTC: true, | ||
TimeFormat: time.RFC3339, | ||
Skipper: func(c *gin.Context) bool { | ||
return c.Request.URL.Path == "/ping" && c.Request.Method == "GET" | ||
}, | ||
})) | ||
|
||
// Example ping request. | ||
r.GET("/ping", func(c *gin.Context) { | ||
c.Writer.Header().Add("X-Request-Id", "1234-5678-9012") | ||
c.String(200, "pong "+fmt.Sprint(time.Now().Unix())) | ||
}) | ||
|
||
r.POST("/ping", func(c *gin.Context) { | ||
c.Writer.Header().Add("X-Request-Id", "9012-5678-1234") | ||
c.String(200, "pong "+fmt.Sprint(time.Now().Unix())) | ||
}) | ||
|
||
// Listen and Server in 0.0.0.0:8080 | ||
if err := r.Run(":8080"); err != nil { | ||
panic(err) | ||
} | ||
} |