v0.0.227 error on duplicate exerr.ErrorType

This commit is contained in:
Mike Schwörer 2023-08-08 15:28:29 +02:00
parent 4a3f25baa0
commit 376c6cab50
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 26 additions and 15 deletions

View File

@ -7,6 +7,9 @@ type SyncSet[TData comparable] struct {
lock sync.Mutex
}
// Add adds `value` to the set
// returns true if the value was actually inserted
// returns false if the value already existed
func (s *SyncSet[TData]) Add(value TData) bool {
s.lock.Lock()
defer s.lock.Unlock()
@ -15,10 +18,10 @@ func (s *SyncSet[TData]) Add(value TData) bool {
s.data = make(map[TData]bool)
}
_, ok := s.data[value]
_, existsInPreState := s.data[value]
s.data[value] = true
return !ok
return !existsInPreState
}
func (s *SyncSet[TData]) AddAll(values []TData) {

View File

@ -1,6 +1,7 @@
package exerr
import (
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
@ -37,25 +38,32 @@ type ErrorType struct {
//goland:noinspection GoUnusedGlobalVariable
var (
TypeInternal = ErrorType{"INTERNAL_ERROR", langext.Ptr(500)}
TypePanic = ErrorType{"PANIC", langext.Ptr(500)}
TypeNotImplemented = ErrorType{"NOT_IMPLEMENTED", langext.Ptr(500)}
TypeInternal = NewType("INTERNAL_ERROR", langext.Ptr(500))
TypePanic = NewType("PANIC", langext.Ptr(500))
TypeNotImplemented = NewType("NOT_IMPLEMENTED", langext.Ptr(500))
TypeWrap = ErrorType{"Wrap", nil}
TypeWrap = NewType("Wrap", nil)
TypeBindFailURI = ErrorType{"BINDFAIL_URI", langext.Ptr(400)}
TypeBindFailQuery = ErrorType{"BINDFAIL_QUERY", langext.Ptr(400)}
TypeBindFailJSON = ErrorType{"BINDFAIL_JSON", langext.Ptr(400)}
TypeBindFailFormData = ErrorType{"BINDFAIL_FORMDATA", langext.Ptr(400)}
TypeBindFailHeader = ErrorType{"BINDFAIL_HEADER", langext.Ptr(400)}
TypeBindFailURI = NewType("BINDFAIL_URI", langext.Ptr(400))
TypeBindFailQuery = NewType("BINDFAIL_QUERY", langext.Ptr(400))
TypeBindFailJSON = NewType("BINDFAIL_JSON", langext.Ptr(400))
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", langext.Ptr(400))
TypeBindFailHeader = NewType("BINDFAIL_HEADER", langext.Ptr(400))
TypeUnauthorized = ErrorType{"UNAUTHORIZED", langext.Ptr(401)}
TypeAuthFailed = ErrorType{"AUTH_FAILED", langext.Ptr(401)}
TypeUnauthorized = NewType("UNAUTHORIZED", langext.Ptr(401))
TypeAuthFailed = NewType("AUTH_FAILED", langext.Ptr(401))
// other values come from pkgconfig
)
var registeredTypes = dataext.SyncSet[string]{}
func NewType(key string, defStatusCode *int) ErrorType {
insertOkay := registeredTypes.Add(key)
if !insertOkay {
panic("Cannot register same ErrType ('" + key + "') more than once")
}
return ErrorType{key, defStatusCode}
}

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.226"
const GoextVersion = "0.0.227"
const GoextVersionTimestamp = "2023-08-08T14:28:09+0200"
const GoextVersionTimestamp = "2023-08-08T15:28:29+0200"