Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
futuretea committed Aug 26, 2019
0 parents commit e203574
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor
yapidoc
17 changes: 17 additions & 0 deletions Dockerfile
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"]

21 changes: 21 additions & 0 deletions LICENSE
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.
18 changes: 18 additions & 0 deletions Makefile
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
30 changes: 30 additions & 0 deletions README.md
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).
54 changes: 54 additions & 0 deletions conf/conf.go
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()
}
29 changes: 29 additions & 0 deletions conf/listen.go
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,
)
}
19 changes: 19 additions & 0 deletions conf/yapi.go
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
}
5 changes: 5 additions & 0 deletions config.yaml
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 added docs/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions go.mod
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
)
Loading

0 comments on commit e203574

Please sign in to comment.