-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from dongxuny/master
Bump up rk-entry version to v2.0.3
- Loading branch information
Showing
18 changed files
with
1,547 additions
and
8 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
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,23 @@ | ||
.PHONY: all | ||
all: lint fmt swag | ||
|
||
.PHONY: lint | ||
lint: | ||
@echo "[golangci-lint] Running golangci-lint..." | ||
@golangci-lint run 2>&1 | ||
@echo "------------------------------------[Done]" | ||
|
||
.PHONY: fmt | ||
fmt: | ||
@echo "[fmt] Format go project..." | ||
@gofmt -s -w . 2>&1 | ||
@echo "------------------------------------[Done]" | ||
|
||
.PHONY: swag | ||
swag: | ||
@echo "[swag] Running swag..." | ||
@swag init --generalInfo main.go --propertyStrategy camelcase | ||
@rm -rf docs/docs.go | ||
@echo "------------------------------------[Done]" | ||
|
||
|
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,131 @@ | ||
# Example | ||
Middleware & bootstrapper designed for [gogf/gf](https://github.com/gogf/gf) web framework. | ||
|
||
## Documentation | ||
- [Github](https://github.com/rookie-ninja/rk-gin) | ||
- [Official Docs]() will be updated for v2 soon | ||
|
||
 | ||
|
||
## Installation | ||
- rk-boot: Bootstrapper base | ||
- rk-gf: Bootstrapper for [gogf/gf](https://github.com/gogf/gf) | ||
|
||
```shell | ||
go get github.com/rookie-ninja/rk-boot/v2 | ||
go get github.com/rookie-ninja/rk-gf | ||
``` | ||
|
||
## Quick start | ||
### 1.Create boot.yaml | ||
```yaml | ||
--- | ||
gf: | ||
- name: greeter # Required | ||
port: 8080 # Required | ||
enabled: true # Required | ||
commonService: | ||
enabled: true # Optional, default: false | ||
sw: | ||
enabled: true # Optional, default: false | ||
docs: | ||
enabled: true # Optional, default: false | ||
``` | ||
### 2.Create main.go | ||
```go | ||
// Copyright (c) 2021 rookie-ninja | ||
// | ||
// Use of this source code is governed by an Apache-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/gogf/gf/v2/net/ghttp" | ||
"github.com/rookie-ninja/rk-boot/v2" | ||
"github.com/rookie-ninja/rk-gf/boot" | ||
"net/http" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample rk-demo server. | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @securityDefinitions.basic BasicAuth | ||
|
||
// @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 | ||
func main() { | ||
// Create a new boot instance. | ||
boot := rkboot.NewBoot() | ||
|
||
// Register handler | ||
entry := rkgf.GetGfEntry("greeter") | ||
entry.Server.BindHandler("/v1/greeter", Greeter) | ||
|
||
// Bootstrap | ||
boot.Bootstrap(context.TODO()) | ||
|
||
boot.WaitForShutdownSig(context.TODO()) | ||
} | ||
|
||
// Greeter handler | ||
// @Summary Greeter service | ||
// @Id 1 | ||
// @version 1.0 | ||
// @produce application/json | ||
// @Param name query string true "Input name" | ||
// @Success 200 {object} GreeterResponse | ||
// @Router /v1/greeter [get] | ||
func Greeter(ctx *ghttp.Request) { | ||
ctx.Response.WriteHeader(http.StatusOK) | ||
ctx.Response.WriteJson(&GreeterResponse{ | ||
Message: fmt.Sprintf("Hello %s!", ctx.GetQuery("name").String()), | ||
}) | ||
} | ||
|
||
type GreeterResponse struct { | ||
Message string | ||
} | ||
``` | ||
|
||
### 3.Start server | ||
|
||
```go | ||
$ go run main.go | ||
``` | ||
|
||
### 4.Validation | ||
- Call API: | ||
|
||
```shell script | ||
$ curl -X GET localhost:8080/v1/greeter?name=rk-dev | ||
{"Message":"Hello rk-dev!"} | ||
|
||
$ curl -X GET localhost:8080/rk/v1/ready | ||
{ | ||
"ready": true | ||
} | ||
|
||
$ curl -X GET localhost:8080/rk/v1/alive | ||
{ | ||
"alive": true | ||
} | ||
``` | ||
|
||
- Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) | ||
|
||
 | ||
|
||
- Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) | ||
|
||
 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,61 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is a sample rk-demo 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" | ||
}, | ||
"paths": { | ||
"/v1/greeter": { | ||
"get": { | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Greeter service", | ||
"operationId": "1", | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "Input name", | ||
"name": "name", | ||
"in": "query", | ||
"required": true | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/main.GreeterResponse" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"main.GreeterResponse": { | ||
"type": "object", | ||
"properties": { | ||
"message": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BasicAuth": { | ||
"type": "basic" | ||
} | ||
} | ||
} |
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,40 @@ | ||
definitions: | ||
main.GreeterResponse: | ||
properties: | ||
message: | ||
type: string | ||
type: object | ||
info: | ||
contact: | ||
email: [email protected] | ||
name: API Support | ||
url: http://www.swagger.io/support | ||
description: This is a sample rk-demo server. | ||
license: | ||
name: Apache 2.0 | ||
url: http://www.apache.org/licenses/LICENSE-2.0.html | ||
termsOfService: http://swagger.io/terms/ | ||
title: Swagger Example API | ||
version: "1.0" | ||
paths: | ||
/v1/greeter: | ||
get: | ||
operationId: "1" | ||
parameters: | ||
- description: Input name | ||
in: query | ||
name: name | ||
required: true | ||
type: string | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: OK | ||
schema: | ||
$ref: '#/definitions/main.GreeterResponse' | ||
summary: Greeter service | ||
securityDefinitions: | ||
BasicAuth: | ||
type: basic | ||
swagger: "2.0" |
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,71 @@ | ||
module github.com/rookie-ninja/rk-demo | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/rookie-ninja/rk-boot/v2 v2.0.1 | ||
github.com/rookie-ninja/rk-gf v1.0.0 | ||
) | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.0.0 // indirect | ||
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/clbanning/mxj/v2 v2.5.5 // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/fsnotify/fsnotify v1.5.1 // indirect | ||
github.com/go-logr/logr v1.2.2 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-redis/redis/v8 v8.11.4 // indirect | ||
github.com/go-sql-driver/mysql v1.6.0 // indirect | ||
github.com/gogf/gf/v2 v2.0.0-rc3 // indirect | ||
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/kr/pretty v0.2.1 // indirect | ||
github.com/magiconair/properties v1.8.5 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/mattn/go-runewidth v0.0.9 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mitchellh/mapstructure v1.4.3 // indirect | ||
github.com/olekukonko/tablewriter v0.0.5 // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v1.12.1 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.32.1 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
github.com/rookie-ninja/rk-entry/v2 v2.0.3 // indirect | ||
github.com/rookie-ninja/rk-logger v1.2.10 // indirect | ||
github.com/rookie-ninja/rk-query v1.2.11 // indirect | ||
github.com/spf13/afero v1.6.0 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.10.1 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
go.opentelemetry.io/contrib v1.4.0 // indirect | ||
go.opentelemetry.io/otel v1.4.1 // indirect | ||
go.opentelemetry.io/otel/exporters/jaeger v1.4.1 // indirect | ||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.4.1 // indirect | ||
go.opentelemetry.io/otel/sdk v1.4.1 // indirect | ||
go.opentelemetry.io/otel/trace v1.4.1 // indirect | ||
go.uber.org/atomic v1.7.0 // indirect | ||
go.uber.org/multierr v1.6.0 // indirect | ||
go.uber.org/ratelimit v0.2.0 // indirect | ||
go.uber.org/zap v1.21.0 // indirect | ||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect | ||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect | ||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
gopkg.in/ini.v1 v1.66.2 // indirect | ||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.