👔 Make the just added service status up & running

This commit is contained in:
LittleSheep 2025-03-29 13:51:53 +08:00
parent 488793a2dc
commit 69012b9cc3
2 changed files with 14 additions and 4 deletions

View File

@ -2,14 +2,15 @@ package directory
import ( import (
"context" "context"
"math/rand"
"time"
"git.solsynth.dev/hypernet/nexus/pkg/internal/kv" "git.solsynth.dev/hypernet/nexus/pkg/internal/kv"
"git.solsynth.dev/hypernet/nexus/pkg/nex" "git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/goccy/go-json" "github.com/goccy/go-json"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
clientv3 "go.etcd.io/etcd/client/v3" clientv3 "go.etcd.io/etcd/client/v3"
"math/rand"
"time"
) )
const ServiceInfoKvPrefix = "nexus.service/" const ServiceInfoKvPrefix = "nexus.service/"
@ -22,6 +23,7 @@ func AddServiceInstance(in *ServiceInstance) error {
} }
_, err = kv.Kv.Put(context.Background(), key, string(data)) _, err = kv.Kv.Put(context.Background(), key, string(data))
SetServiceStatus(in.Type, true)
return err return err
} }

View File

@ -6,8 +6,10 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
var statusOfServices = make(map[string]bool) var (
var statusLock sync.Mutex statusOfServices = make(map[string]bool)
statusLock sync.Mutex
)
func GetServiceStatus() map[string]bool { func GetServiceStatus() map[string]bool {
out := make(map[string]bool) out := make(map[string]bool)
@ -25,6 +27,12 @@ func GetServiceStatus() map[string]bool {
return out return out
} }
func SetServiceStatus(t string, status bool) {
statusLock.Lock()
defer statusLock.Unlock()
statusOfServices[t] = status
}
func ValidateServices() { func ValidateServices() {
statusLock.Lock() statusLock.Lock()
defer statusLock.Unlock() defer statusLock.Unlock()