aboutsummaryrefslogtreecommitdiff
path: root/model/app.go
blob: 89d656d916dfb5c757f3c83b3d67bfc699388bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package model

import (
	"errors"
	"strings"
)

var (
	ErrAppNotFound = errors.New("app not found")
)

type App struct {
	InstanceDomain string
	InstanceURL    string
	ClientID       string
	ClientSecret   string
}

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
}