examples

command
v0.0.0-...-4645e4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2019 License: MIT Imports: 9 Imported by: 0

README

Ignitor examples

Configuration

See .env.yml . Modify it according to your environment.

locale: zh_cn
timezone: Asia/Shanghai
dbhost: '127.0.0.1'
dbport: 5432
dbname: ignitor
dbuser: ignitor
dbpassword: goignitor

Create users table

Create table ignitor_users with 3 columns.

  • id - int primary key
  • username - varchar(30)
  • password - varchar(256)

Run

$ go run main.go
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /user-info                --> main.main.func1 (3 handlers)
[GIN-debug] POST   /users                    --> main.main.func2 (3 handlers)
[GIN-debug] GET    /config                   --> main.main.func3 (3 handlers)
[GIN-debug] GET    /panic                    --> main.main.func4 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8765

Send requests

$ curl -H "X-Auth-Token:admin" -H "X-Auth-Username:admin" http://localhost:8765/config\?getters\=tz
{"code":"AuthError","data":null,"msg":"error","status":"SUCCESS"}
$ curl -H "X-Auth-Token:admin123456" -H "X-Auth-Username:admin" http://localhost:8765/config\?getters\=tz
{"code":"SUCCESS","data":{"tz":"Asia/Shanghai"},"msg":"success","status":"SUCCESS"}
$ curl --data "username=1_&password=123" http://localhost:8765/users
{"code":"ParamError","data":{"password":["password should contains at least 6 characters"],"username":["username should contains 3-30 characters","shouldn't contain '_'"]},"msg":"error","status":"SUCCESS"}
$ curl --data "username=orange&password=Orange" http://localhost:8765/users
{"code":"SUCCESS","data":{"username":"orange"},"msg":"success","status":"SUCCESS"}
$ curl http://localhost:8765/user-info?username=orange
{"code":"SUCCESS","data":{"error":null,"user":{"id":4,"username":"orange","password":"Orange"}},"msg":"success","status":"SUCCESS"}
$ curl http://localhost:8765/config?getters=locale
{"code":"SUCCESS","data":{"locale":"zh_cn"},"msg":"success","status":"SUCCESS"}
$ curl http://localhost:8765/config?getters=locale,tz
{"code":"SUCCESS","data":{"locale":"zh_cn","tz":"Asia/Shanghai"},"msg":"success","status":"SUCCESS"}

Develop

see main.go

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL