// 注册到 Eureka,goeureka会自动30秒发送一次心跳
package main
import (
"fmt"
"github.com/SimonWang00/goeureka"
"github.com/gin-gonic/gin"
"github.com/robfig/cron/v3"
"time"
"wbGo/configs"
)
type Dades struct {
Id int
Name string
Age 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 main
import (
"fmt"
"github.com/SimonWang00/goeureka"
"time"
"wbGo/configs"
)
type Dades struct {
Id int
Name string
Age 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
registerToEureka()
// 每隔 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)
}