Skip to content
Snippets Groups Projects
Select Git revision
  • 00724aff2bcbdb66f2dfb2dd4be581fec9bc5d98
  • master default protected
  • renovate/golang-1.x
  • renovate/go-1.x
  • renovate/github.com-mattn-go-sqlite3-1.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/git.autistici.org-ai3-go-common-digest
  • better-compression
8 results

config.go

Blame
    • ale's avatar
      bb99d517
      Simplify internal interfaces · bb99d517
      ale authored
      Clear separation between configuration and its parsed results, which
      are now maintained in the RuntimeContext to kept them consistent
      within backup/restore jobs.
      bb99d517
      History
      Simplify internal interfaces
      ale authored
      Clear separation between configuration and its parsed results, which
      are now maintained in the RuntimeContext to kept them consistent
      within backup/restore jobs.
    pointstore.go 856 B
    package main
    
    import (
    	"errors"
    	"sort"
    	"sync"
    )
    
    var (
    	errPointNotFound = errors.New("point does not exist")
    )
    
    type pointStore struct {
    	pointMap map[string]*point
    	lock     *sync.RWMutex
    }
    
    func newPointStore() *pointStore {
    	return &pointStore{
    		pointMap: make(map[string]*point),
    		lock:     &sync.RWMutex{},
    	}
    }
    
    func (ps *pointStore) keys() []string {
    	ps.lock.Lock()
    	keys := make([]string, 0)
    	for k := range ps.pointMap {
    		keys = append(keys, k)
    	}
    	sort.Strings(keys)
    	ps.lock.Unlock()
    	return keys
    }
    
    func (ps *pointStore) set(p *point) error {
    	var err error
    	ps.lock.Lock()
    	ps.pointMap[p.key()] = p
    	ps.lock.Unlock()
    	return err
    }
    
    func (ps *pointStore) get(name string) (*point, error) {
    	ps.lock.Lock()
    	if p, ok := ps.pointMap[name]; ok {
    		ps.lock.Unlock()
    		return p, nil
    	}
    	ps.lock.Unlock()
    	return &point{}, errPointNotFound
    }