Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
package api
import (
"context"
"github.com/pkg/errors"
"github.com/usememos/memos/store"
)
// BuildUserName returns the canonical public resource name for a user.
func BuildUserName(username string) string {
return UserNamePrefix + username
}
func parseUsernameFromName(name string) (string, error) {
tokens, err := GetNameParentTokens(name, UserNamePrefix)
if err != nil {
return "", err
}
username := tokens[0]
if username == "" {
return "", errors.Errorf("invalid user name %q", name)
}
return username, nil
}
// ResolveUserByName resolves a username-based user resource name to a store user.
func ResolveUserByName(ctx context.Context, stores *store.Store, name string) (*store.User, error) {
username, err := parseUsernameFromName(name)
if err != nil {
return nil, err
}
user, err := stores.GetUser(ctx, &store.FindUser{Username: &username})
if err != nil {
return nil, errors.Wrap(err, "resolve user by name: GetUser failed")
}
return user, nil
}