-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit e203574
Showing
17 changed files
with
551 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
vendor | ||
yapidoc |
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,17 @@ | ||
FROM golang:1.11 AS builder | ||
ADD ./ /src | ||
WORKDIR /src | ||
RUN make | ||
|
||
FROM alpine:3.9.2 | ||
RUN sed -i "s|http://dl-cdn.alpinelinux.org|https://mirrors.aliyun.com|g" /etc/apk/repositories \ | ||
&& apk update \ | ||
&& apk add tzdata | ||
ENV TZ=Asia/Shanghai | ||
RUN mkdir -p /app | ||
WORKDIR /app | ||
COPY templates ./templates | ||
COPY config.yaml ./config.yaml | ||
COPY --from=builder /src/yapidoc . | ||
CMD [ "./yapidoc", "--config", "./config.yaml"] | ||
|
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 futuretea | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,18 @@ | ||
all: clean vendor build | ||
.PHONY: init vendor build run clean lint | ||
init: | ||
go mod init github.com/futuretea/yapidoc | ||
vendor: | ||
GOPROXY=https://goproxy.io go mod vendor | ||
docker: | ||
docker build -t futuretea/yapidoc . | ||
build: | ||
CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -o yapidoc | ||
run: | ||
go run main.go | ||
test: | ||
docker run -it --rm --net=host futuretea/yapidoc | ||
lint: | ||
golangci-lint run | ||
clean: | ||
rm -rf yapidoc |
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,30 @@ | ||
# yapidoc | ||
yapidoc is a doc server for [YMFE/Yapi](https://github.com/YMFE/yapi) . | ||
|
||
## Usage | ||
1. run a yapidoc server using docker | ||
```bash | ||
docker run -itd --name yapidoc -e YAPI_URL=your_yapi_url -p 8888:8888 futuretea/yapidoc | ||
``` | ||
2. download doc from the yapidoc server | ||
```javascript | ||
http://127.0.0.1:8888/projects/your_project_token?tag=your_api_tag | ||
``` | ||
|
||
3. stop the yapidoc server | ||
```bash | ||
docker stop yapidoc | ||
docker rm yapidoc | ||
``` | ||
|
||
## Documentation | ||
- [FAQ](https://github.com/futuretea/yapidoc/wiki/FAQ) | ||
|
||
## Related Projects | ||
- [YMFE/yapi](https://github.com/YMFE/yapi) - docker image for Yapi | ||
- [futuretea/go-yapi](https://godoc.org/github.com/futuretea/go-yapi) - Go client library for YMFE/Yapi | ||
- [futuretea/yapi](https://github.com/futuretea/yapi) - docker image for YMFE/Yapi | ||
|
||
## License | ||
|
||
This project is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License). |
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,54 @@ | ||
package conf | ||
|
||
import ( | ||
"github.com/futuretea/yapidoc/logs" | ||
|
||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ( | ||
config *viper.Viper | ||
) | ||
|
||
func readString(keys ...string) string { | ||
var result = "" | ||
for _, key := range keys { | ||
result = config.GetString(key) | ||
if result != "" { | ||
return result | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func readInt(keys ...string) int { | ||
var result = 0 | ||
for _, key := range keys { | ||
result = config.GetInt(key) | ||
if result != 0 { | ||
return result | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func init() { | ||
config = viper.New() | ||
//bind cmdline | ||
pflag.String("config", "config.yaml", "config file") | ||
pflag.Parse() | ||
err := config.BindPFlags(pflag.CommandLine) | ||
if err != nil { | ||
logs.Fatal("bind cmdline err", err) | ||
} | ||
|
||
//read file | ||
config.SetConfigFile(config.GetString("config")) | ||
if err := config.ReadInConfig(); err != nil { | ||
logs.Fatal("read config file err", err) | ||
} | ||
|
||
//get env | ||
config.AutomaticEnv() | ||
} |
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,29 @@ | ||
package conf | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
//ListenConfigStruct 监听信息 | ||
type ListenConfigStruct struct { | ||
Host string | ||
Port int | ||
} | ||
|
||
func readListen() *ListenConfigStruct { | ||
listenConfig := ListenConfigStruct{ | ||
Host: readString("LISTEN_HOST", "listen.host"), | ||
Port: readInt("LISTEN_PORT", "listen.port"), | ||
} | ||
return &listenConfig | ||
} | ||
|
||
//GetListenURL 获取监听信息 | ||
func GetListenURL() string { | ||
listenConfig := readListen() | ||
return fmt.Sprintf( | ||
"%s:%d", | ||
listenConfig.Host, | ||
listenConfig.Port, | ||
) | ||
} |
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,19 @@ | ||
package conf | ||
|
||
//YapiConfig Yapi信息 | ||
type YapiConfig struct { | ||
URL string | ||
} | ||
|
||
func readYapi() *YapiConfig { | ||
yapiConfig := YapiConfig{ | ||
URL: readString("YAPI_URL", "yapi.url"), | ||
} | ||
return &yapiConfig | ||
} | ||
|
||
//GetYapiURL 获取Yapi信息 | ||
func GetYapiURL() string { | ||
yapiConfig := readYapi() | ||
return yapiConfig.URL | ||
} |
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,5 @@ | ||
listen: | ||
host: 0.0.0.0 | ||
port: 8888 | ||
yapi: | ||
url: http://127.0.0.1:3000 |
Empty file.
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,11 @@ | ||
module github.com/futuretea/yapidoc | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/futuretea/go-yapi v0.0.0-20190826164710-159b136173f9 | ||
github.com/gin-gonic/gin v1.4.0 | ||
github.com/rs/zerolog v1.15.0 | ||
github.com/spf13/pflag v1.0.3 | ||
github.com/spf13/viper v1.4.0 | ||
) |
Oops, something went wrong.