Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
qloog committed Jul 18, 2018
1 parent db75015 commit 6d8b2cf
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ _testmain.go
.idea

# custom
go-api
goapi
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /bin/bash
BASEDIR = $(shell pwd)

# build with verison infos
versionDir = "apiserver/pkg/version"
versionDir = "goapi/pkg/version"
gitTag = $(shell if [ "`git describe --tags --abbrev=0 2>/dev/null`" != "" ];then git describe --tags --abbrev=0; else git log --pretty=format:'%h' -n 1; fi)
buildDate = $(shell TZ=Asia/Shanghai date +%FT%T%z)
gitCommit = $(shell git log --pretty=format:'%H' -n 1)
Expand All @@ -13,11 +13,11 @@ ldflags="-w -X ${versionDir}.gitTag=${gitTag} -X ${versionDir}.buildDate=${build
all: gotool
@go build -v -ldflags ${ldflags} .
clean:
rm -f apiserver
rm -f goapi
find . -name "[._]*.s[a-w][a-z]" | xargs -i rm -f {}
gotool:
gofmt -w .
go tool vet . |& grep -v vendor;true
go tool vet . | grep -v vendor;true

swag-init:
swag init
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
最终源码文件
goapi 框架

适合于开发Go项目
2 changes: 1 addition & 1 deletion admin.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SERVER="go-api"
SERVER="goapi"
BASE_DIR=$PWD
INTERVAL=2

Expand Down
4 changes: 2 additions & 2 deletions conf/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
runmode: debug # 开发模式, debug, release, test
addr: :8080 # HTTP绑定端口
name: go-api # API Server的名字
name: goapi # API Server的名字
url: http://127.0.0.1:8080 # pingServer函数请求的API服务器的ip:port
max_ping_count: 10 # pingServer函数try的次数
jwt_secret: Rtg8BPKNEf2mB4mgvKONGPZZQSaJWNLijxR42qRgq0iBb5
Expand All @@ -11,7 +11,7 @@ tls:
log:
writers: stdout
logger_level: DEBUG
logger_file: log/go-api.log
logger_file: log/goapi.log
log_format_text: true
rollingPolicy: size
log_rotate_date: 1
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (c *Config) initConfig() error {
viper.AddConfigPath("conf") // 如果没有指定配置文件,则解析默认的配置文件
viper.SetConfigName("config")
}
viper.SetConfigType("yaml") // 设置配置文件格式为YAML
viper.AutomaticEnv() // 读取匹配的环境变量
viper.SetEnvPrefix("APISERVER") // 读取环境变量的前缀为APISERVER
viper.SetConfigType("yaml") // 设置配置文件格式为YAML
viper.AutomaticEnv() // 读取匹配的环境变量
viper.SetEnvPrefix("goapi") // 读取环境变量的前缀为goapi
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
if err := viper.ReadInConfig(); err != nil { // viper解析配置文件
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2018-06-18 02:15:43.723659228 +0800 CST m=+0.040196270
// 2018-07-16 13:00:21.828146863 +0800 CST m=+0.031649098

package docs

Expand Down
8 changes: 4 additions & 4 deletions docs/swagger/swagger.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"swagger": "2.0",
"info": {
"description": "apiserver demo",
"title": "Apiserver Example API",
"description": "goapi demo",
"title": "goapi Example API",
"contact": {
"name": "lkong",
"name": "qloog",
"url": "http://www.swagger.io/support",
"email": "466701708@qq.com"
"email": "449128759@qq.com"
},
"license": {},
"version": "1.0"
Expand Down
2 changes: 1 addition & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handler
import (
"net/http"

"go-api/pkg/errno"
"goapi/pkg/errno"

"github.com/gin-gonic/gin"
)
Expand Down
8 changes: 4 additions & 4 deletions handler/user/create.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package user

import (
. "go-api/handler"
"go-api/model"
"go-api/pkg/errno"
"go-api/util"
. "goapi/handler"
"goapi/model"
"goapi/pkg/errno"
"goapi/util"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
Expand Down
6 changes: 3 additions & 3 deletions handler/user/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package user
import (
"strconv"

. "go-api/handler"
"go-api/model"
"go-api/pkg/errno"
. "goapi/handler"
"goapi/model"
"goapi/pkg/errno"

"github.com/gin-gonic/gin"
)
Expand Down
9 changes: 6 additions & 3 deletions handler/user/get.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package user

import (
. "go-api/handler"
"go-api/model"
"go-api/pkg/errno"
. "goapi/handler"
"goapi/model"
"goapi/pkg/errno"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
)

// @Summary Get an user by the user identifier
Expand All @@ -17,6 +18,8 @@ import (
// @Success 200 {object} model.UserModel "{"code":0,"message":"OK","data":{"username":"kong","password":"$2a$10$E0kwtmtLZbwW/bDQ8qI8e.eHPqhQOW9tvjwpyo/p05f/f4Qvr3OmS"}}"
// @Router /user/{username} [get]
func Get(c *gin.Context) {
log.Info("Get function called.")

username := c.Param("username")
// Get the user by the `username` from the database.
user, err := model.GetUser(username)
Expand Down
6 changes: 3 additions & 3 deletions handler/user/list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package user

import (
. "go-api/handler"
"go-api/pkg/errno"
"go-api/service"
. "goapi/handler"
"goapi/pkg/errno"
"goapi/service"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
Expand Down
10 changes: 5 additions & 5 deletions handler/user/login.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package user

import (
. "go-api/handler"
"go-api/model"
"go-api/pkg/auth"
"go-api/pkg/errno"
"go-api/pkg/token"
. "goapi/handler"
"goapi/model"
"goapi/pkg/auth"
"goapi/pkg/errno"
"goapi/pkg/token"

"github.com/gin-gonic/gin"
)
Expand Down
8 changes: 4 additions & 4 deletions handler/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package user
import (
"strconv"

. "go-api/handler"
"go-api/model"
"go-api/pkg/errno"
"go-api/util"
. "goapi/handler"
"goapi/model"
"goapi/pkg/errno"
"goapi/util"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
Expand Down
2 changes: 1 addition & 1 deletion handler/user/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package user

import (
"go-api/model"
"goapi/model"
)

type CreateRequest struct {
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"os"
"time"

"go-api/config"
"go-api/model"
v "go-api/pkg/version"
"go-api/router"
"go-api/router/middleware"
"goapi/config"
"goapi/model"
v "goapi/pkg/version"
"goapi/router"
"goapi/router/middleware"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
Expand All @@ -22,13 +22,13 @@ import (
)

var (
cfg = pflag.StringP("config", "c", "", "go-api config file path.")
cfg = pflag.StringP("config", "c", "", "goapi config file path.")
version = pflag.BoolP("version", "v", false, "show version info.")
)

// @title Apiserver Example API
// @title goapi Example API
// @version 1.0
// @description apiserver demo
// @description goapi demo

// @contact.name lkong
// @contact.url http://www.swagger.io/support
Expand Down
4 changes: 2 additions & 2 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package model
import (
"fmt"

"go-api/pkg/auth"
"go-api/pkg/constvar"
"goapi/pkg/auth"
"goapi/pkg/constvar"

validator "gopkg.in/go-playground/validator.v9"
)
Expand Down
6 changes: 3 additions & 3 deletions router/middleware/auth.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package middleware

import (
"go-api/handler"
"go-api/pkg/errno"
"go-api/pkg/token"
"goapi/handler"
"goapi/pkg/errno"
"goapi/pkg/token"

"github.com/gin-gonic/gin"
)
Expand Down
4 changes: 2 additions & 2 deletions router/middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"regexp"
"time"

"go-api/handler"
"go-api/pkg/errno"
"goapi/handler"
"goapi/pkg/errno"

"github.com/gin-gonic/gin"
"github.com/lexkong/log"
Expand Down
8 changes: 4 additions & 4 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package router
import (
"net/http"

_ "go-api/docs" // docs is generated by Swag CLI, you have to import it.
"go-api/handler/sd"
"go-api/handler/user"
"go-api/router/middleware"
_ "goapi/docs" // docs is generated by Swag CLI, you have to import it.
"goapi/handler/sd"
"goapi/handler/user"
"goapi/router/middleware"

"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
Expand Down
4 changes: 2 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"sync"

"go-api/model"
"go-api/util"
"goapi/model"
"goapi/util"
)

func ListUser(username string, offset, limit int) ([]*model.UserInfo, uint64, error) {
Expand Down
2 changes: 1 addition & 1 deletion wrktest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
API 性能测试脚本,会自动执行 wrk 命令,采集数据、分析数据并调用 gnuplot 画图
使用方式 ( 测试 API 性能):
1. 启动 apiserver (8080端口)
1. 启动 goapi (8080端口)
2. 执行测试脚本: ./wrktest.sh
脚本会生成 _wrk.dat 的数据文件,每列含义为:
Expand Down

0 comments on commit 6d8b2cf

Please sign in to comment.