Example #1
0
func FindKeyByName(name string) (*AccessKey, error) {
	res, _, err := DB.Run(ql.NewRWCtx(), `
		SELECT name, mailbox, fullAccess, token
		FROM accessToken
		WHERE name == $1
		LIMIT 1;
	`, name)
	if err != nil {
		return nil, err
	}
	key := &AccessKey{}
	res[0].Do(false, func(data []interface{}) (bool, error) {
		ql.Unmarshal(key, data)
		return false, nil
	})
	return key, nil
}
Example #2
0
func AllKeys() ([]*AccessKey, error) {
	res, _, err := DB.Run(ql.NewRWCtx(), `
		SELECT 	name, mailbox, fullAccess, token
		FROM 		accessToken`)
	if err != nil {
		return nil, err
	}
	keys := []*AccessKey{}
	err = res[0].Do(false, func(data []interface{}) (bool, error) {
		key := &AccessKey{}
		if err := ql.Unmarshal(key, data); err != nil {
			return false, err
		}
		keys = append(keys, key)
		return true, nil
	})
	return keys, nil
}