Skip to content

Commit

Permalink
Develop
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 authored and easonlin committed Jun 25, 2017
1 parent dce16ba commit 1e97bf3
Show file tree
Hide file tree
Showing 19 changed files with 882 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go

go:
- 1.8.x

before_install:
- go get -t -v ./...

script:
- go test -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
40 changes: 40 additions & 0 deletions example/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package api

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/swag-gonic/swag/example/web"
)

//
// @Summary Add a new pet to the store
// @Description get string by ID
// @Accept json
// @Produce json
// @Param some_id path int true "Some ID"
// @Success 200 {string} string "ok"
// @Failure 400 {object} web.APIError "We need ID!!"
// @Failure 404 {object} web.APIError "Can not find ID"
// @Router /testapi/get-string-by-int/{some_id} [get]
func GetStringByInt(c *gin.Context) {
err := web.APIError{}
fmt.Println(err)
}

// @Description get struct array by ID
// @Accept json
// @Produce json
// @Param some_id path string true "Some ID"
// @Param offset query int true "Offset"
// @Param limit query int true "Offset"
// @Success 200 {string} string "ok"
// @Failure 400 {object} web.APIError "We need ID!!"
// @Failure 404 {object} web.APIError "Can not find ID"
// @Router /testapi/get-struct-array-by-string/{some_id} [get]
func GetStructArrayByString(c *gin.Context) {

}

type Pet3 struct {
ID int `json:"id"`
}
161 changes: 161 additions & 0 deletions example/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swag-gonic/swag at
// 2017-06-25 01:25:37.872454531 +0800 CST

package docs

import (
"github.com/swag-gonic/swag/swagger"
)

var doc = `{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server.",
"title": "Swagger Example API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "petstore.swagger.io",
"basePath": "/v2",
"paths": {
"/testapi/get-string-by-int/{some_id}": {
"get": {
"description": "get string by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Add a new pet to the store",
"parameters": [
{
"description": "Some ID",
"name": "some_id",
"in": "path",
"required": true,
"schema": {
"type": "int"
}
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"type": "string"
}
},
"400": {
"description": "We need ID!!",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
},
"404": {
"description": "Can not find ID",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
}
}
}
},
"/testapi/get-struct-array-by-string/{some_id}": {
"get": {
"description": "get struct array by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"description": "Some ID",
"name": "some_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Offset",
"name": "offset",
"in": "query",
"required": true,
"schema": {
"type": "int"
}
},
{
"description": "Offset",
"name": "limit",
"in": "query",
"required": true,
"schema": {
"type": "int"
}
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"type": "string"
}
},
"400": {
"description": "We need ID!!",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
},
"404": {
"description": "Can not find ID",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
}
}
}
}
},
"definitions": {
"web.APIError": {
"type": "object",
"properties": {
"ErrorCode": {
"type": "int"
},
"ErrorMessage": {
"type": "string"
}
}
}
}
}`

type s struct{}

func (s *s) ReadDoc() string {
return doc
}
func init() {
swagger.Register(swagger.Name, &s{})
}
31 changes: 31 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"github.com/gin-gonic/gin"
"github.com/swag-gonic/gin-swagger"
"github.com/swag-gonic/gin-swagger/swaggerFiles"

_ "github.com/swag-gonic/gin-swagger/example/docs"
)

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io
// @BasePath /v2
func main() {
r := gin.New()

r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

r.Run()
}
27 changes: 27 additions & 0 deletions example/web/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package web

// @hello
// yo yo yo yo
type Pet struct {
ID int `json:"id"`
Category struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"category"`
Name string `json:"name"`
PhotoUrls []string `json:"photoUrls"`
Tags []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"tags"`
Status string `json:"status"`
}

type Pet2 struct {
ID int `json:"id"`
}

type APIError struct {
ErrorCode int
ErrorMessage string
}
Loading

0 comments on commit 1e97bf3

Please sign in to comment.