Common API
Enable Common API
Overview#
Common service contains builtin API commonly used by user.
Path | Description |
---|---|
/rk/v1/alive | K8S liveness。 |
/rk/v1/ready | K8S readiness。 |
/rk/v1/info | Get Application Info。 |
/rk/v1/gc | Trigger GC。 |
Install#
go get github.com/rookie-ninja/rk-boot/v2
go get github.com/rookie-ninja/rk-gf
CommonService options#
name | description | type | default value |
---|---|---|---|
gf.commonService.enabled | Enable Common API | boolean | false |
gf.commonService.pathPrefix | Common API path prefix | string | /rk/v1 |
Quick start#
1.Create boot.yaml#
---
gf:
- name: greeter
port: 8080
enabled: true
commonService:
enabled: true
# pathPrefix: ""
2.Create main.go#
package main
import (
"context"
"github.com/rookie-ninja/rk-boot/v2"
_ "github.com/rookie-ninja/rk-gf/boot"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}
3.Validate#
$ curl localhost:8080/rk/v1/ready
{
"ready": true
}
Cheers#
4.Enable swagger UI#
---
gf:
- name: greeter
port: 8080
enabled: true
commonService:
enabled: true
sw:
enabled: true
Validate