Skip to content

Commit

Permalink
fix: update travis step and file organization (swaggo#59)
Browse files Browse the repository at this point in the history
* file organization

* create Makefile(lint, build, test, deps)

* update travis step

* fix lint error

* update readme
  • Loading branch information
pei0804 authored and easonlin404 committed Mar 5, 2018
1 parent aa3348b commit bbb969f
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 371 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
swag
example/simple/docs

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

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea
.idea
.vscode

# Etc
.DS_Store
1 change: 1 addition & 0 deletions .golint_exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^example
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ go:
- 1.10.x

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

script:
- make lint
- make build
- make test
- go test -race -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/make
GOCMD=$(shell which go)
GOLINT=$(shell which golint)
GOIMPORT=$(shell which goimports)
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOLIST=$(GOCMD) list
BINARY_NAME=swag

all: test build

build:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/...

test:
$(GOTEST) -v ./...

clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)

DIRS=$(shell $(GOLIST) -f {{.Dir}} ./...)
lint:
@for d in $(DIRS) ; do \
if [ "`$(GOIMPORT) -l $$d/*.go | tee /dev/stderr`" ]; then \
echo "^ - Repo contains improperly formatted go files" && echo && exit 1; \
fi \
done
@if [ "`$(GOLINT) ./... | grep -vf .golint_exclude | tee /dev/stderr`" ]; then \
echo "^ - Lint errors!" && echo && exit 1; \
fi

deps:
$(GOGET) -v ./...
$(GOGET) github.com/stretchr/testify/assert
$(GOGET) github.com/golang/lint/golint
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ type Pet3 struct {
```

## Supported Web Framework
- [gin-swagger](http://github.com/swaggo/gin-swagger)
- [echo-swagger](http://github.com/swaggo/echo-swagger)
- [gin](http://github.com/swaggo/gin-swagger)
- [echo](http://github.com/swaggo/echo-swagger)
- [net/http](https://github.com/swaggo/http-swagger)
- revel

## Limitation
- Not supported for array of structs
Expand Down
4 changes: 2 additions & 2 deletions cmd/swag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func main() {
Usage: "create docs.go",
Action: func(c *cli.Context) error {
searchDir := "./"
mainApiFile := "./main.go"
gen.New().Build(searchDir, mainApiFile)
mainAPIFile := "./main.go"
gen.New().Build(searchDir, mainAPIFile)
return nil
},
},
Expand Down
Binary file removed cmd/swag/swag
Binary file not shown.
276 changes: 0 additions & 276 deletions example/simple/docs/docs.go

This file was deleted.

6 changes: 3 additions & 3 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func New() *Gen {
return &Gen{}
}

// Build builds swagger json file for gived searchDir and mainApiFile. Returns json
func (g *Gen) Build(searchDir, mainApiFile string) (string, error) {
// Build builds swagger json file for gived searchDir and mainAPIFile. Returns json
func (g *Gen) Build(searchDir, mainAPIFile string) (string, error) {
log.Println("Generate swagger docs....")
p := swag.New()
p.ParseApi(searchDir, mainApiFile)
p.ParseAPI(searchDir, mainAPIFile)
swagger := p.GetSwagger()

b, _ := json.MarshalIndent(swagger, "", " ")
Expand Down
Loading

0 comments on commit bbb969f

Please sign in to comment.