Files
zeekayandHanzo Dev aa87442fdd Record upstream authorship centrally in NOTICE instead of in every file header
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the
Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in
NOTICE, alongside LICENSE. The header lint accepts any copyright line above the
SPDX line, so it no longer demands an upstream one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 17:50:35 -07:00

70 lines
1.3 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package nosql
import (
"context"
"strconv"
"sync"
"time"
"github.com/hanzoai/git/modules/process"
"github.com/hanzokv/go/v9"
)
var manager *Manager
// Manager is the nosql connection manager
type Manager struct {
ctx context.Context
finished process.FinishedFunc
mutex sync.Mutex
KVConnections map[string]*kvClientHolder
}
type kvClientHolder struct {
kv.UniversalClient
name []string
count int64
}
func (r *kvClientHolder) Close() error {
return manager.CloseKVClient(r.name[0])
}
func init() {
_ = GetManager()
}
// GetManager returns a Manager and initializes one as singleton is there's none yet
func GetManager() *Manager {
if manager == nil {
ctx, _, finished := process.GetManager().AddTypedContext(context.Background(), "Service: NoSQL", process.SystemProcessType, false)
manager = &Manager{
ctx: ctx,
finished: finished,
KVConnections: make(map[string]*kvClientHolder),
}
}
return manager
}
func valToTimeDuration(vs []string) (result time.Duration) {
var err error
for _, v := range vs {
result, err = time.ParseDuration(v)
if err != nil {
var val int
val, err = strconv.Atoi(v)
result = time.Duration(val)
}
if err == nil {
return result
}
}
return result
}