diff options
| author | Max Resnick <max@ofmax.li> | 2020-11-08 11:45:16 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2021-01-01 10:50:14 -0800 |
| commit | a397341ad471cc761f7fb930d77e53cf7eb40a2a (patch) | |
| tree | 76fb8318269569687fdd30467dc61ecba3499d09 /internal/db/redis/acct.go | |
| parent | 689a57ec4a444f8233fe2e5ec7ceb0903218218d (diff) | |
| download | iserv-a397341ad471cc761f7fb930d77e53cf7eb40a2a.tar.gz | |
adds casbin and accounts
Diffstat (limited to 'internal/db/redis/acct.go')
| -rw-r--r-- | internal/db/redis/acct.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/db/redis/acct.go b/internal/db/redis/acct.go new file mode 100644 index 0000000..72df741 --- /dev/null +++ b/internal/db/redis/acct.go @@ -0,0 +1,44 @@ +package redis + +import ( + "fmt" + + "github.com/gomodule/redigo/redis" + "github.com/pkg/errors" + + "git.ofmax.li/iserv/internal/acct" +) + +// AcctRepo account +type AcctRepo struct { + db *redis.Pool +} + +var ( + acctProfileKey string = "acct:email:%s" +) + +// NewAcctRepo account repo +func NewAcctRepo(conn *redis.Pool) *AcctRepo { + return &AcctRepo{ + conn, + } +} + +// UpdateAcctProfile write profile to redis +func (db *AcctRepo) UpdateAcctProfile(p acct.Profile) error { + conn := db.db.Get() + defer conn.Close() + profileID, profileKeyValues := p.ProfileKeyValues() + acctProfileKey := fmt.Sprintf(acctProfileKey, profileID) + profileArgs := redis.Args{}.Add(acctProfileKey).AddFlat(profileKeyValues) + res, err := redis.String(conn.Do("HMSET", profileArgs...)) + if err != nil { + fmt.Print(err) + return err + } + if res != "OK" { + return errors.Errorf("%s acct was not saved", acctProfileKey) + } + return nil +} |