Files
2025-12-13 14:20:47 +08:00
..
2025-12-13 13:47:10 +08:00
2025-12-13 13:47:10 +08:00
2025-12-13 14:20:47 +08:00

Registrar

The Registrar is the service discovery system of the DysonNetwork. Here are a port to the Golang in order to support other Golang services.

To use the system, try build with these API:

package main

import (
	"log"
	"os"
	"os/signal"
	"syscall"

	"yourmodule/registry"
)

func main() {
	endpoints := []string{"localhost:2379"}

	registrar, err := registry.NewServiceRegistrar(endpoints)
	if err != nil {
		log.Fatalf("Error creating registrar: %v", err)
	}

	serviceName := "orders"
	host := "10.0.0.5"
	port := 5000
	ttl := int64(30)

	err = registrar.Register(serviceName, host, port, ttl)
	if err != nil {
		log.Fatalf("Register error: %v", err)
	}
	log.Println("Service registered")

	// Wait for termination
	stop := make(chan os.Signal, 1)
	signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
	<-stop

	err = registrar.Deregister()
	if err != nil {
		log.Printf("Deregister error: %v", err)
	} else {
		log.Println("Service deregistered")
	}
}