mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-01 09:34:21 +00:00
Use filesystem based kv store instead of sqlite
This commit is contained in:
parent
3b50f40c08
commit
59aad78f66
11 changed files with 217 additions and 88 deletions
33
model/app.go
33
model/app.go
|
@ -1,19 +1,40 @@
|
|||
package model
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrAppNotFound = errors.New("app not found")
|
||||
)
|
||||
|
||||
type App struct {
|
||||
InstanceURL string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
InstanceDomain string
|
||||
InstanceURL string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
}
|
||||
|
||||
type AppRepository interface {
|
||||
Add(app App) (err error)
|
||||
Update(instanceURL string, clientID string, clientSecret string) (err error)
|
||||
Get(instanceURL string) (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
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
package model
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrSessionNotFound = errors.New("session not found")
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
ID string
|
||||
InstanceURL string
|
||||
AccessToken string
|
||||
ID string
|
||||
InstanceDomain string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
type SessionRepository interface {
|
||||
|
@ -21,3 +24,26 @@ type SessionRepository interface {
|
|||
func (s Session) IsLoggedIn() bool {
|
||||
return len(s.AccessToken) > 0
|
||||
}
|
||||
|
||||
func (s *Session) Marshal() []byte {
|
||||
str := s.InstanceDomain + "\n" + s.AccessToken
|
||||
return []byte(str)
|
||||
}
|
||||
|
||||
func (s *Session) Unmarshal(id string, data []byte) error {
|
||||
str := string(data)
|
||||
lines := strings.Split(str, "\n")
|
||||
|
||||
size := len(lines)
|
||||
if size == 1 {
|
||||
s.InstanceDomain = lines[0]
|
||||
} else if size == 2 {
|
||||
s.InstanceDomain = lines[0]
|
||||
s.AccessToken = lines[1]
|
||||
} else {
|
||||
return errors.New("invalid data")
|
||||
}
|
||||
|
||||
s.ID = id
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue