-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init swaggo/swag ; helps to make swagger docs
- Loading branch information
1 parent
0ef8278
commit 71d8521
Showing
8 changed files
with
210 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,78 @@ var doc = `{ | |
"info": { | ||
"description": "{{.Description}}", | ||
"title": "{{.Title}}", | ||
"contact": {}, | ||
"contact": { | ||
"name": "readytowork", | ||
"url": "http://readytowork.jp", | ||
"email": "[email protected]" | ||
}, | ||
"license": {}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": {} | ||
"paths": { | ||
"/posts/create": { | ||
"post": { | ||
"description": "Add Posts", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Add Posts", | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "name search by q", | ||
"name": "q", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/model.Post" | ||
} | ||
}, | ||
"headers": { | ||
"Token": { | ||
"type": "string", | ||
"description": "qwerty" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"model.Post": { | ||
"type": "object", | ||
"required": [ | ||
"Description", | ||
"Title" | ||
], | ||
"properties": { | ||
"Description": { | ||
"type": "string" | ||
}, | ||
"Title": { | ||
"type": "string" | ||
}, | ||
"createdAt": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}` | ||
|
||
type swaggerInfo struct { | ||
|
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 |
---|---|---|
@@ -1,8 +1,73 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"contact": {}, | ||
"contact": { | ||
"name": "readytowork", | ||
"url": "http://readytowork.jp", | ||
"email": "[email protected]" | ||
}, | ||
"license": {} | ||
}, | ||
"paths": {} | ||
"paths": { | ||
"/posts/create": { | ||
"post": { | ||
"description": "Add Posts", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Add Posts", | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "name search by q", | ||
"name": "q", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/model.Post" | ||
} | ||
}, | ||
"headers": { | ||
"Token": { | ||
"type": "string", | ||
"description": "qwerty" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"model.Post": { | ||
"type": "object", | ||
"required": [ | ||
"Description", | ||
"Title" | ||
], | ||
"properties": { | ||
"Description": { | ||
"type": "string" | ||
}, | ||
"Title": { | ||
"type": "string" | ||
}, | ||
"createdAt": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,47 @@ | ||
definitions: | ||
model.Post: | ||
properties: | ||
Description: | ||
type: string | ||
Title: | ||
type: string | ||
createdAt: | ||
type: string | ||
id: | ||
type: string | ||
required: | ||
- Description | ||
- Title | ||
type: object | ||
info: | ||
contact: {} | ||
contact: | ||
email: [email protected] | ||
name: readytowork | ||
url: http://readytowork.jp | ||
license: {} | ||
paths: {} | ||
paths: | ||
/posts/create: | ||
post: | ||
consumes: | ||
- application/json | ||
description: Add Posts | ||
parameters: | ||
- description: name search by q | ||
in: query | ||
name: q | ||
type: string | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: OK | ||
headers: | ||
Token: | ||
description: qwerty | ||
type: string | ||
schema: | ||
items: | ||
$ref: '#/definitions/model.Post' | ||
type: array | ||
summary: Add Posts | ||
swagger: "2.0" |
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 |
---|---|---|
|
@@ -3,29 +3,39 @@ package main | |
import ( | ||
"fmt" | ||
"github/bhattaraibishal50/blog/common" | ||
"github/bhattaraibishal50/blog/docs" | ||
"github/bhattaraibishal50/blog/middleware" | ||
|
||
"github.com/gin-gonic/gin" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/thinkerou/favicon" | ||
|
||
ginSwagger "github.com/swaggo/gin-swagger" | ||
|
||
// gin-swagger middleware | ||
swaggerFiles "github.com/swaggo/files" | ||
ginSwagger "github.com/swaggo/gin-swagger" | ||
) | ||
|
||
// swagger embed files | ||
// @contact.name readytowork | ||
// @contact.url http://readytowork.jp | ||
// @contact.email [email protected] | ||
|
||
func main() { | ||
//setting up the application | ||
// programmatically set swagger info | ||
docs.SwaggerInfo.Title = "Blog Application" | ||
docs.SwaggerInfo.Description = "This is a sample server for Blog Application" | ||
docs.SwaggerInfo.Version = "1.0" | ||
docs.SwaggerInfo.Host = "localhost:8080" | ||
docs.SwaggerInfo.BasePath = "/" | ||
docs.SwaggerInfo.Schemes = []string{"http", "https"} | ||
|
||
fmt.Println("UUID ::", common.GetNewUUID()) | ||
r := gin.Default() | ||
r.Use(favicon.New("./public/favicon.ico")) // set favicon middleware | ||
|
||
// set routes | ||
middleware.SetRoutes(r) | ||
PORT := ":8080" | ||
|
||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) | ||
r.Run(PORT) //listen and serve on 0.0.0.0:8080 by default | ||
} |
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
Binary file not shown.