Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 001be56

Browse files
authored
Merge pull request #19 from ansionfor/master
更新readme说明,增加curl示例
2 parents 3cb4d3d + fd93269 commit 001be56

File tree

3 files changed

+52
-32
lines changed

3 files changed

+52
-32
lines changed

README.md

+25-17
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,27 @@ Import
2121
import "github.com/gogf/gf-jwt"
2222
```
2323

24-
## Example
25-
26-
Check demo [example/auth/auth.go](example/auth/auth.go) and use `ExtractClaims` to customize user data.
27-
28-
[embedmd]:# (example/auth/auth.go go)
29-
30-
3124
## Demo
3225

33-
Run `example/server/server.go` on the `8000` port.
26+
Run `example/main.go` on the `8000` port.
3427

3528
```bash
36-
$ go run example/server/server.go
29+
$ go run example/main.go
3730
```
3831

3932
![api screenshot](screenshot/server.png)
4033

41-
Test the effect on the command line via [httpie](https://github.com/jkbrzt/httpie).
34+
Test the effect on the command line via [httpie](https://github.com/jkbrzt/httpie) or curl.
4235

4336
### Login interface:
4437

4538
```bash
4639
$ http -v --form POST localhost:8000/login username=admin password=admin
4740
```
41+
or
42+
```bash
43+
$ curl -X POST -d 'username=admin&password=admin' localhost:8000/login
44+
```
4845

4946
Command line output
5047

@@ -53,19 +50,27 @@ Command line output
5350
### Refresh token interface:
5451

5552
```bash
56-
$ http -v -f GET localhost:8000/user/refresh_token "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
53+
$ http -v -f GET localhost:8000/refresh_token "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
54+
```
55+
or
56+
```bash
57+
$ curl -H 'Authorization:Bearer xxxxxxxxx' -X POST localhost:8000/refresh_token
5758
```
5859

5960
Command line output
6061

6162
![api screenshot](screenshot/refresh_token.png)
6263

63-
### hello interface
64+
### User info interface
6465

65-
We test the return of the hello interface with the username `admin` and password `admin`
66+
We test the return of the info interface with the username `admin` and password `admin`
6667

6768
```bash
68-
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
69+
$ http -f GET localhost:8000/user/info "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
70+
```
71+
or
72+
```bash
73+
$ curl -H 'Authorization:Bearer xxxxxx' -X POST localhost:8000/user/info
6974
```
7075

7176
Command line output
@@ -77,12 +82,15 @@ Command line output
7782
We use an unauthorized token to test the return of the hello interface.
7883

7984
```bash
80-
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
85+
$ http -f GET localhost:8000/user/info "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
86+
```
87+
or
88+
```
89+
curl -H 'Authorization:Bearer xxxxxx' -X POST localhost:8000/user/info
8190
```
8291

8392
Command line output
8493

8594
![api screenshot](screenshot/401.png)
8695

87-
88-
Thanks again [https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)
96+
Thanks again [https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)

README_zh.md

+26-14
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,28 @@ $ go get github.com/gogf/gf-jwt
2121
import "github.com/gogf/gf-jwt"
2222
```
2323

24-
## 例子
25-
26-
查看示例 [example/auth/auth.go](example/auth/auth.go) , 使用 `ExtractClaims` 可以自定义用户数据.
27-
28-
[embedmd]:# (example/auth/auth.go go)
29-
3024
## Demo
3125

32-
运行 `example/server/server.go``8000`端口.
26+
运行 `example/main.go``8000`端口.
3327

3428
```bash
35-
$ go run example/server/server.go
29+
$ go run example/main.go
3630
```
3731

3832
![api screenshot](screenshot/server.png)
3933

40-
通过 [httpie](https://github.com/jkbrzt/httpie) ,在命令行来测试下效果.
34+
通过 [httpie](https://github.com/jkbrzt/httpie) 或者 curl, 在命令行来测试下效果.
4135

4236
### 登录接口:
4337

4438
```bash
4539
$ http -v --form POST localhost:8000/login username=admin password=admin
4640
```
41+
或者
42+
```bash
43+
$ curl -X POST -d 'username=admin&password=admin' localhost:8000/login
44+
```
45+
4746

4847
命令行输出
4948

@@ -52,19 +51,28 @@ $ http -v --form POST localhost:8000/login username=admin password=admin
5251
### 刷新 token 接口:
5352

5453
```bash
55-
$ http -v -f GET localhost:8000/user/refresh_token "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
54+
$ http -v -f GET localhost:8000/refresh_token "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
55+
```
56+
或者
57+
```bash
58+
$ curl -H 'Authorization:Bearer xxxxxxxxx' -X POST localhost:8000/refresh_token
5659
```
5760

61+
5862
命令行输出
5963

6064
![api screenshot](screenshot/refresh_token.png)
6165

62-
### hello 接口
66+
### 用户验证接口
6367

6468
我们使用用户名 `admin` 和密码 `admin` 测试一下 hello 接口的返回
6569

6670
```bash
67-
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
71+
$ http -f GET localhost:8000/user/info "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
72+
```
73+
或者
74+
```bash
75+
$ curl -H 'Authorization:Bearer xxxxxx' -X POST localhost:8000/user/info
6876
```
6977

7078
命令行输出
@@ -76,12 +84,16 @@ $ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Conte
7684
我们用未授权的 token 来测试 hello 接口的返回
7785

7886
```bash
79-
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
87+
$ http -f GET localhost:8000/user/info "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
88+
```
89+
或者
90+
```bash
91+
$ curl -H 'Authorization:Bearer xxxxxx' -X POST localhost:8000/user/info
8092
```
8193

8294
命令行输出
8395

8496
![api screenshot](screenshot/401.png)
8597

8698

87-
再次感谢[https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)
99+
再次感谢[https://github.com/appleboy/gin-jwt](https://github.com/appleboy/gin-jwt)

example/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ func main() {
2525
g.Middleware(service.Middleware.CORS, middlewareAuth)
2626
g.ALL("/info", api.Work.Info)
2727
})
28-
s.SetPort(8111)
28+
s.SetPort(8000)
2929
s.Run()
3030
}

0 commit comments

Comments
 (0)