Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Dec 11, 2024
1 parent e10605f commit 3f0dd90
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ k3dserver: k3d image
kubectl apply -f misc/deploy.yaml
sleep 2 ; kubectl logs -f xreg-server

prof: server qtest
prof: server
@# May need to install: apt-get install graphviz
NO_DELETE_REGISTRY=1 \
go test -cpuprofile cpu.prof -memprofile mem.prof -bench . \
Expand Down
23 changes: 0 additions & 23 deletions registry/httpStuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,6 @@ type Server struct {
HTTPServer *http.Server
}

var DefaultRegDbSID string

func GetDefaultReg(tx *Tx) *Registry {
if tx == nil {
var err error
tx, err = NewTx()
Must(err)
}

reg, err := FindRegistryBySID(tx, DefaultRegDbSID)
Must(err)

if reg != nil {
tx.Registry = reg
}

return reg
}

func NewServer(port int) *Server {
server := &Server{
Port: port,
Expand Down Expand Up @@ -116,10 +97,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
tx.Rollback()
}()

if DefaultRegDbSID == "" {
panic("No registry specified")
}

saveVerbose := log.GetVerbose()
if tmp := r.URL.Query().Get("verbose"); tmp != "" {
if v, err := strconv.Atoi(tmp); err == nil {
Expand Down
4 changes: 3 additions & 1 deletion registry/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func ParseRequest(tx *Tx, w http.ResponseWriter, r *http.Request) (*RequestInfo,

info.HTTPWriter = DefaultHTTPWriter(info)

defer func() { log.VPrintf(3, "Info:\n%s\n", ToJSON(info)) }()
if log.GetVerbose() > 2 {
defer func() { log.VPrintf(3, "Info:\n%s\n", ToJSON(info)) }()
}

if tmp := r.Header.Get("xRegistry~User"); tmp != "" {
tx.User = tmp
Expand Down
23 changes: 23 additions & 0 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ type Registry struct {
Model *Model
}

var DefaultRegDbSID string

func GetDefaultReg(tx *Tx) *Registry {
if DefaultRegDbSID == "" {
panic("No registry specified")
}

if tx == nil {
var err error
tx, err = NewTx()
Must(err)
}

reg, err := FindRegistryBySID(tx, DefaultRegDbSID)
Must(err)

if reg != nil {
tx.Registry = reg
}

return reg
}

func (r *Registry) Rollback() error {
if r != nil {
return r.tx.Rollback()
Expand Down

0 comments on commit 3f0dd90

Please sign in to comment.