mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
First commit
This commit is contained in:
54
pkg/goutils/goutils.go
Normal file
54
pkg/goutils/goutils.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package goutils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
)
|
||||
|
||||
type NotAnInteger struct {
|
||||
message string
|
||||
}
|
||||
|
||||
func (m *NotAnInteger) Error() string {
|
||||
return m.message
|
||||
}
|
||||
|
||||
func InterfaceToInt(i interface{}) (val int, err error) {
|
||||
|
||||
err = nil
|
||||
val = 0
|
||||
|
||||
switch t := i.(type) {
|
||||
case int:
|
||||
val = t
|
||||
case int8:
|
||||
val = int(t) // standardizes across systems
|
||||
case int16:
|
||||
val = int(t) // standardizes across systems
|
||||
case int32:
|
||||
val = int(t) // standardizes across systems
|
||||
case int64:
|
||||
val = int(t) // standardizes across systems
|
||||
case float32:
|
||||
val = int(t) // standardizes across systems
|
||||
case float64:
|
||||
val = int(t) // standardizes across systems
|
||||
case uint8:
|
||||
val = int(t) // standardizes across systems
|
||||
case uint16:
|
||||
val = int(t) // standardizes across systems
|
||||
case uint32:
|
||||
val = int(t) // standardizes across systems
|
||||
case uint64:
|
||||
val = int(t) // standardizes across systems
|
||||
default:
|
||||
err = &NotAnInteger{"count attribute is not an integer"}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CopyMap(dest, src map[string]interface{}) {
|
||||
buf := new(bytes.Buffer)
|
||||
gob.NewEncoder(buf).Encode(src)
|
||||
gob.NewDecoder(buf).Decode(&dest)
|
||||
}
|
||||
Reference in New Issue
Block a user