// 注册到 Eureka,goeureka会自动30秒发送一次心跳
package mainimport ("fmt""github.com/SimonWang00/goeureka""github.com/gin-gonic/gin""github.com/robfig/cron/v3""time""wbGo/configs"
)type Dades struct {Id intName stringAge int
}func main() {//连接数据库configs.BaseName("wbrj_sample")var data []Dades//查询configs.Db.Raw("select * from dade where id>=?", 1).Find(&data)fmt.Printf("%+v", data[0].Id)for _, v := range data {fmt.Println(v.Id)}// 注册到 Eureka,goeureka会自动30秒发送一次心跳registerToEureka()r := gin.Default()r.Run()
}func registerToEureka() {// 实现注册到 Eureka 的逻辑,30秒一次心跳fmt.Println("注册到 Eureka")opt := make(map[string]string)goeureka.RegisterClient("http://127.0.0.1:6868", "", "myGoApp", "8000", "43", opt)
}
不需要定时任务
package mainimport ("fmt""github.com/SimonWang00/goeureka""time""wbGo/configs"
)type Dades struct {Id intName stringAge int
}func main() {//连接数据库configs.BaseName("wbrj_sample")var data []Dades//查询configs.Db.Raw("select * from dade where id>=?", 1).Find(&data)fmt.Printf("%+v", data[0].Id)for _, v := range data {fmt.Println(v.Id)}// 注册到 EurekaregisterToEureka()// 每隔 30 秒发送心跳ticker := time.NewTicker(30 * time.Second)defer ticker.Stop()for range ticker.C {registerToEureka()}
}func registerToEureka() {// 实现注册到 Eureka 的逻辑,30秒一次心跳fmt.Println("注册到 Eureka")opt := make(map[string]string)goeureka.RegisterClient("http://127.0.0.1:6868", "", "myGoApp", "8000", "43", opt)
}