mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-11 22:38:45 +00:00
Use json format for app and session repo
This commit is contained in:
parent
a25d64a078
commit
e73eb1162a
4 changed files with 34 additions and 56 deletions
27
model/app.go
27
model/app.go
|
@ -2,7 +2,6 @@ package model
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -10,31 +9,13 @@ var (
|
|||
)
|
||||
|
||||
type App struct {
|
||||
InstanceDomain string
|
||||
InstanceURL string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
InstanceDomain string `json:"instance_domain"`
|
||||
InstanceURL string `json:"instance_url"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
}
|
||||
|
||||
type AppRepository interface {
|
||||
Add(app App) (err error)
|
||||
Get(instanceDomain string) (app App, err error)
|
||||
}
|
||||
|
||||
func (a *App) Marshal() []byte {
|
||||
str := a.InstanceURL + "\n" + a.ClientID + "\n" + a.ClientSecret
|
||||
return []byte(str)
|
||||
}
|
||||
|
||||
func (a *App) Unmarshal(instanceDomain string, data []byte) error {
|
||||
str := string(data)
|
||||
lines := strings.Split(str, "\n")
|
||||
if len(lines) != 3 {
|
||||
return errors.New("invalid data")
|
||||
}
|
||||
a.InstanceDomain = instanceDomain
|
||||
a.InstanceURL = lines[0]
|
||||
a.ClientID = lines[1]
|
||||
a.ClientSecret = lines[2]
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue