modify makefile to automatically install tools and generate api docs

This commit is contained in:
HaoyangLiu 2018-09-13 19:56:23 +08:00
parent 76469c082e
commit 5f38b50a85
10 changed files with 31 additions and 18 deletions

View File

@ -32,7 +32,7 @@ TMP_BUILD_TAGS := $(BUILD_TAGS)
BUILD_TAGS = $(filter-out ledger, $(TMP_BUILD_TAGS))
endif
build: check-ledger
build: check-ledger update_gaia_lite_docs
ifeq ($(OS),Windows_NT)
go build $(BUILD_FLAGS) -o build/gaiad.exe ./cmd/gaia/cmd/gaiad
go build $(BUILD_FLAGS) -o build/gaiacli.exe ./cmd/gaia/cmd/gaiacli
@ -44,6 +44,9 @@ endif
build-linux:
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
update_gaia_lite_docs:
@statik -src=client/lcd/swaggerui -dest=client/lcd
build_cosmos-sdk-cli:
ifeq ($(OS),Windows_NT)
go build $(BUILD_FLAGS) -o build/cosmos-sdk-cli.exe ./cmd/cosmos-sdk-cli
@ -64,7 +67,7 @@ else
go build $(BUILD_FLAGS) -o build/democli ./examples/democoin/cmd/democli
endif
install: check-ledger
install: check-ledger update_gaia_lite_docs
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiad
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiacli

View File

@ -278,7 +278,7 @@ type RecoverKeyBody struct {
}
// RecoverKeyResuestHandler is the handler of creating seed in swagger rest server
func RecoverKeyResuestHandler(w http.ResponseWriter, r *http.Request) {
func RecoverKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
var m RecoverKeyBody

View File

@ -34,7 +34,7 @@ func Commands() *cobra.Command {
func RegisterRoutes(r *mux.Router) {
r.HandleFunc("/keys", QueryKeysRequestHandler).Methods("GET")
r.HandleFunc("/keys", AddNewKeyRequestHandler).Methods("POST")
r.HandleFunc("/keys/{name}/recover", RecoverKeyResuestHandler).Methods("POST")
r.HandleFunc("/keys/{name}/recover", RecoverKeyRequestHandler).Methods("POST")
r.HandleFunc("/keys/{name}/sign", SignResuest).Methods("POST")
r.HandleFunc("/keys/{name}", GetKeyRequestHandler).Methods("GET")
r.HandleFunc("/keys/{name}", UpdateKeyRequestHandler).Methods("PUT")

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,6 @@
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host": "localhost:1317",
"basePath": "/",
"paths": {
"/txs": {

View File

@ -4,19 +4,15 @@ Due to the rest handlers and related data structures are distributed in many sub
## Steps
1. Install the command line tool first.
1. Install the swagger-ui generate tool first.
```
go get github.com/rakyll/statik
make update_dev_tools
```
2. Edit API docs
1. Directly Edit API docs manually: `client/lcd/swaggerui/swagger.json`
2. Edit API docs within this [SwaggerHub](https://app.swaggerhub.com). Please refer to this [document](https://app.swaggerhub.com/help/index) for how to use the about website to edit API docs.
3. Download `swagger.json` and replace the old `swagger.json` under `client/lcd/swaggerui` folds
4. Regenerate `client/lcd/statik/statik.go` file
```
rm client/lcd/statik/statik.go && statik -src=client/lcd/swaggerui -dest=client/lcd
```
5. Compile new gaiacli
4. Compile new gaiacli
```
make install
```

View File

@ -13,6 +13,7 @@ MISSPELL = github.com/client9/misspell/cmd/misspell
ERRCHECK = github.com/kisielk/errcheck
UNPARAM = mvdan.cc/unparam
GOCYCLO = github.com/alecthomas/gocyclo
STATIK = github.com/rakyll/statik
DEP_CHECK := $(shell command -v dep 2> /dev/null)
GOLINT_CHECK := $(shell command -v golint 2> /dev/null)
@ -23,6 +24,7 @@ MISSPELL_CHECK := $(shell command -v misspell 2> /dev/null)
ERRCHECK_CHECK := $(shell command -v errcheck 2> /dev/null)
UNPARAM_CHECK := $(shell command -v unparam 2> /dev/null)
GOCYCLO_CHECK := $(shell command -v gocyclo 2> /dev/null)
STATIK_CHECK := $(shell command -v statik 2> /dev/null)
check_tools:
ifndef DEP_CHECK
@ -73,6 +75,11 @@ ifndef GOCYCLO_CHECK
else
@echo "Found gocyclo in path."
endif
ifndef STATIK_CHECK
@echo "No statik in path. Install with 'make get_tools'."
else
@echo "Found statik in path."
endif
get_tools:
ifdef DEP_CHECK
@ -132,6 +139,12 @@ else
@echo "Installing gocyclo"
go get -v $(GOCYCLO)
endif
ifndef STATIK_CHECK
@echo "No statik in path. Install with 'make get_tools'."
else
@echo "Installing statik"
go get -v $(STATIK)
endif
update_tools:
@echo "Updating dep"
@ -155,6 +168,8 @@ update_dev_tools:
go get -u -v $(UNPARAM)
@echo "Updating goyclo"
go get -u -v $(GOCYCLO)
@echo "Updating statik"
go get -u -v $(STATIK)
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.

View File

@ -18,12 +18,12 @@ import (
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, storeName string) {
r.HandleFunc(
"/bank/balances/{address}",
QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
QueryBalancesRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
).Methods("GET")
}
// query balances Handler
func QueryAccountRequestHandlerFn(
func QueryBalancesRequestHandlerFn(
storeName string, cdc *wire.Codec,
decoder auth.AccountDecoder, cliCtx context.CLIContext,
) http.HandlerFunc {

View File

@ -10,5 +10,5 @@ import (
// RegisterRoutes registers bank-related REST handlers to a router
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
registerQueryRoutes(cliCtx, r, cdc, "acc")
RegisterSendTxRoutes(cliCtx, r, cdc, kb)
registerSendTxRoutes(cliCtx, r, cdc, kb)
}

View File

@ -17,8 +17,8 @@ import (
"github.com/gorilla/mux"
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterSendTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
// registerSendTxRoutes - Central function to define routes that get registered by the main application
func registerSendTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/bank/{address}/transfers", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
}