Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shenyu-client-go

Go HTTP register client for Apache ShenYu admin, based on the Java HttpClientRegisterRepository flow.

Features

  • Login to ShenYu admin through GET /platform/login.
  • Cache X-Access-Token per admin server.
  • Register URI, metadata, API doc and discovery config.
  • Send heartbeat and unregister/offline instances.
  • Support multiple ShenYu admin addresses.
  • Optional AES-CBC password encryption compatible with the Java client.

Gin Usage

package main

import (
	"context"
	"log"
	"net/http"

	shenyu "github.com/2sinx/shenyu-client-go"
	"github.com/gin-gonic/gin"
)

func main() {
	app, err := shenyu.New(shenyu.Config{
		Admin:       "http://localhost:9095",
		Username:    "admin",
		Password:    "123456",
		AppName:     "gin-demo",
		ContextPath: "/gin-demo",
		Port:        8082,
	})
	if err != nil {
		log.Fatal(err)
	}

	app.GET("/hello", "hello api", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"message": "hello from gin"})
	})

	if err := app.Run(context.Background()); err != nil {
		log.Fatal(err)
	}
}

shenyu 会在 Run 时自动完成 URI 注册、metadata 注册、heartbeat、退出下线和 Gin server 优雅关闭。

Gin Example

go run ./example

示例服务会启动 GET /hello,并在启动时注册 URI 和 metadata 到 ShenYu admin。 服务注册的 host 可以通过 shenyu.Config.Host 显式配置;如果为空,会按访问 Admin 的本机路由推断,最后退回到非 loopback 网卡 IPv4。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages