mirror of
https://github.com/Theodor-Springmann-Stiftung/lenz-web.git
synced 2025-10-29 01:05:32 +00:00
Public Lib
This commit is contained in:
40
xmlmodels/public.go
Normal file
40
xmlmodels/public.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package xmlmodels
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
xmlparsing "github.com/Theodor-Springmann-Stiftung/lenz-web/xml"
|
||||
)
|
||||
|
||||
var lib *Library
|
||||
var mu sync.RWMutex
|
||||
|
||||
func Set(l *Library) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if lib != nil {
|
||||
panic("Trying to reinitialize Library")
|
||||
}
|
||||
lib = l
|
||||
}
|
||||
|
||||
func Get() *Library {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
if lib == nil {
|
||||
panic("Trying to get uninitialized Library")
|
||||
}
|
||||
return lib
|
||||
}
|
||||
|
||||
func New(dir, hash string) error {
|
||||
Set(NewLibrary())
|
||||
return Parse(dir, hash)
|
||||
}
|
||||
|
||||
func Parse(dir, hash string) error {
|
||||
if hash == "" {
|
||||
return lib.Parse(xmlparsing.Path, dir, hash)
|
||||
}
|
||||
return lib.Parse(xmlparsing.Commit, dir, hash)
|
||||
}
|
||||
Reference in New Issue
Block a user