-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type MyStruct struct { | ||
ID int `json:"id" example:"1" format:"int64"` | ||
// Post name | ||
Name string `json:"name" example:"poti"` | ||
// Post data | ||
Data struct { | ||
// Post tag | ||
Tag []string `json:"name"` | ||
} `json:"data"` | ||
// Integer represented by a string | ||
MyInt int `json:"myint,string"` | ||
} | ||
|
||
// @Summary Call DoSomething | ||
// @Description Does something, but internal (non-exported) fields inside a struct won't be marshaled into JSON | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {string} MyStruct | ||
// @Router /so-something [get] | ||
func DoSomething(c *gin.Context) { | ||
//write your code | ||
} | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server. | ||
// @host localhost:4000 | ||
// @basePath /api | ||
func main() { | ||
r := gin.New() | ||
r.GET("/do-something", api.DoSomething) | ||
r.Run() | ||
} |
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type MyStruct struct { | ||
ID int `json:"id" example:"1" format:"int64"` | ||
// Post name | ||
Name string `json:"name" example:"poti"` | ||
// Post data | ||
Data struct { | ||
// Post tag | ||
Tag []string `json:"name"` | ||
} `json:"data"` | ||
// not-exported variable, for internal use only, not marshaled | ||
internal1 string | ||
internal2 int | ||
internal3 bool | ||
internal4 struct { | ||
NestedInternal string | ||
} | ||
} | ||
|
||
// @Summary Call DoSomething | ||
// @Description Does something, but internal (non-exported) fields inside a struct won't be marshaled into JSON | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {string} MyStruct | ||
// @Router /so-something [get] | ||
func DoSomething(c *gin.Context) { | ||
//write your code | ||
} | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server. | ||
// @host localhost:4000 | ||
// @basePath /api | ||
func main() { | ||
r := gin.New() | ||
r.GET("/do-something", api.DoSomething) | ||
r.Run() | ||
} |
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