37 lines
704 B
Go
37 lines
704 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func GetUUID() uuid.UUID {
|
|
uuid.SetClockSequence(uuid.ClockSequence())
|
|
if uid, err := uuid.NewV7(); err == nil {
|
|
return uid
|
|
}
|
|
uid, _ := uuid.NewUUID()
|
|
return uid
|
|
}
|
|
|
|
type Creds struct {
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func GetCreds() (string, string, error) {
|
|
data, err := os.ReadFile("creds.json")
|
|
if err != nil {
|
|
return "", "", fmt.Errorf("cannot read file creds.json: %v", err)
|
|
}
|
|
var creds = &Creds{}
|
|
err = json.Unmarshal(data, creds)
|
|
if err != nil {
|
|
return "", "", fmt.Errorf("cannot unmarshal data: %v", err)
|
|
}
|
|
return creds.Username, creds.Password, nil
|
|
}
|