mostly functionnal, poorly tested
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/beego/beego/logs"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -9,21 +12,33 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
Me = Identity{uuid.New().String(), "My name", "My key", "MyUrl"}
|
||||
content, err := os.ReadFile("./identity.json")
|
||||
if err != nil {
|
||||
logs.Error("Error when opening file: ", err)
|
||||
}
|
||||
err = json.Unmarshal(content, &Me)
|
||||
if err != nil {
|
||||
logs.Error("Error during Unmarshal(): ", err)
|
||||
}
|
||||
}
|
||||
|
||||
type Identity struct {
|
||||
Id string
|
||||
Name string
|
||||
PublicKey string
|
||||
Url string
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
PrivateKey string `json:"private_key,omitempty"`
|
||||
PublicAttributes Peer `json:"public_attributes,omitempty"`
|
||||
}
|
||||
|
||||
func GetIdentity() (u *Identity) {
|
||||
return &Me
|
||||
}
|
||||
|
||||
func UpdateIdentity(uu *Identity) (a *Identity) {
|
||||
func UpdateIdentity(uu *Identity) error {
|
||||
Me = *uu
|
||||
return &Me
|
||||
jsonBytes, err := json.Marshal(uu)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.WriteFile("./identity.json", jsonBytes, 0600)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user