internal

package
v0.0.0-...-5c4a6e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

Functions

This section is empty.

Types

type API

func NewAPI

func NewAPI(
	logger *zap.Logger,
	hostname string,
	meridianStore Store,
	documentStore *nimona.DocumentStore,
	keygraphStore *nimona.KeygraphStore,
) API

type AuthenticateRequest

type AuthenticateRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type AuthenticateResponse

type AuthenticateResponse struct {
	SessionID string `json:"sessionId"`
	User      *User  `json:"user"`
}

type ContextKey

type ContextKey int
const (
	KeyUsername        ContextKey = iota
	KeyIsAuthenticated ContextKey = iota
)

type CreateNoteRequest

type CreateNoteRequest struct {
	Username  string    `json:"username"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

type CreateNoteResponse

type CreateNoteResponse struct{}

type Follow

type Follow struct {
	Follower  nimona.KeygraphID `gorm:"type:varchar(255);primary_key"`
	Followee  nimona.KeygraphID `gorm:"type:varchar(255);primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type FollowRequest

type FollowRequest struct {
	// TODO: should this be a username?
	KeygraphID       nimona.KeygraphID `json:"keygraph"`
	FolloweeIdentity nimona.KeygraphID `json:"followeeIdentity"`
}

type FollowResponse

type FollowResponse struct{}

type GetFolloweesRequest

type GetFolloweesRequest struct {
	KeygraphID nimona.KeygraphID `json:"keygraph"`
}

type GetFolloweesResponse

type GetFolloweesResponse struct {
	Followees []nimona.KeygraphID `json:"followees"`
}

type GetFollowersRequest

type GetFollowersRequest struct {
	KeygraphID nimona.KeygraphID `json:"keygraph"`
}

type GetFollowersResponse

type GetFollowersResponse struct {
	Followers []nimona.KeygraphID `json:"followers"`
}

type GetNoteRequest

type GetNoteRequest struct {
	NoteID string `json:"noteId"`
}

type GetNoteResponse

type GetNoteResponse struct {
	Note *Note `json:"note"`
}

type GetNotesRequest

type GetNotesRequest struct {
	KeygraphID string `json:"keygraph"`
	// TODO: add filters
	// TODO: add pagination
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

type GetNotesResponse

type GetNotesResponse struct {
	Notes []*Note `json:"notes"`
}

type GetProfileRequest

type GetProfileRequest struct {
	KeygraphID nimona.KeygraphID `json:"keygraph"`
}

type GetProfileResponse

type GetProfileResponse struct {
	KeygraphID nimona.KeygraphID `json:"keygraph"`
	Profile    Profile           `json:"profile"`
}

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

func NewHandlers

func NewHandlers(
	logger *zap.Logger,
	api API,
	store Store,
) *Handlers

func (*Handlers) HandleFollow

func (handlers *Handlers) HandleFollow(w http.ResponseWriter, r *http.Request)

func (*Handlers) HandleIndex

func (handlers *Handlers) HandleIndex(
	w http.ResponseWriter,
	r *http.Request,
)

func (*Handlers) HandleLogin

func (handlers *Handlers) HandleLogin(w http.ResponseWriter, r *http.Request)

func (*Handlers) HandleLogout

func (handlers *Handlers) HandleLogout(w http.ResponseWriter, r *http.Request)

func (*Handlers) HandleNotes

func (handlers *Handlers) HandleNotes(
	w http.ResponseWriter,
	r *http.Request,
)

func (*Handlers) HandleNotesNew

func (handlers *Handlers) HandleNotesNew(
	w http.ResponseWriter,
	r *http.Request,
)

func (*Handlers) HandlePopulate

func (handlers *Handlers) HandlePopulate(
	w http.ResponseWriter,
	r *http.Request,
)

func (*Handlers) HandleProfile

func (handlers *Handlers) HandleProfile(w http.ResponseWriter, r *http.Request)

func (*Handlers) HandleRegister

func (handlers *Handlers) HandleRegister(
	w http.ResponseWriter,
	r *http.Request,
)

func (*Handlers) Register

func (handlers *Handlers) Register(r *chi.Mux)

type NimonaFeed

type NimonaFeed struct {
	Metadata nimona.Metadata `nimona:"$metadata,type=feed"`
	Profile  NimonaProfile   `nimona:"profile,omitempty"`
	Notes    []*NimonaNote   `nimona:"notes,omitempty"`
	Folowees []*NimonaFollow `nimona:"folowees,omitempty"`
}

func (*NimonaFeed) Document

func (t *NimonaFeed) Document() *nimona.Document

func (*NimonaFeed) FromDocument

func (t *NimonaFeed) FromDocument(d *nimona.Document) error

func (*NimonaFeed) FromMap

func (t *NimonaFeed) FromMap(d tilde.Map) error

func (*NimonaFeed) Map

func (t *NimonaFeed) Map() tilde.Map

type NimonaFollow

type NimonaFollow struct {
	Metadata   nimona.Metadata      `nimona:"$metadata,type=follow"`
	KeygraphID nimona.KeygraphID    `nimona:"identity,omitempty"`
	Alias      nimona.IdentityAlias `nimona:"alias,omitempty"`
	Timestamp  string               `nimona:"timestamp,omitempty"`
}

func (*NimonaFollow) Document

func (t *NimonaFollow) Document() *nimona.Document

func (*NimonaFollow) FromDocument

func (t *NimonaFollow) FromDocument(d *nimona.Document) error

func (*NimonaFollow) FromMap

func (t *NimonaFollow) FromMap(d tilde.Map) error

func (*NimonaFollow) Map

func (t *NimonaFollow) Map() tilde.Map

type NimonaNote

type NimonaNote struct {
	Metadata  nimona.Metadata `nimona:"$metadata,type=note"`
	Key       string          `nimona:"_key,omitempty"`
	Partition string          `nimona:"_partition,omitempty"`
	Content   string          `nimona:"content"`
}

func (*NimonaNote) Document

func (t *NimonaNote) Document() *nimona.Document

func (*NimonaNote) FromDocument

func (t *NimonaNote) FromDocument(d *nimona.Document) error

func (*NimonaNote) FromMap

func (t *NimonaNote) FromMap(d tilde.Map) error

func (*NimonaNote) Map

func (t *NimonaNote) Map() tilde.Map

type NimonaProfile

type NimonaProfile struct {
	Metadata    nimona.Metadata       `nimona:"$metadata,type=profile"`
	DisplayName string                `nimona:"displayName,omitempty"`
	Description string                `nimona:"description,omitempty"`
	Alias       *nimona.IdentityAlias `nimona:"alias,omitempty"`
	AvatarURL   string                `nimona:"avatarURL,omitempty"`
}

func (*NimonaProfile) Document

func (t *NimonaProfile) Document() *nimona.Document

func (*NimonaProfile) FromDocument

func (t *NimonaProfile) FromDocument(d *nimona.Document) error

func (*NimonaProfile) FromMap

func (t *NimonaProfile) FromMap(d tilde.Map) error

func (*NimonaProfile) Map

func (t *NimonaProfile) Map() tilde.Map

type Note

type Note struct {
	KeygraphID nimona.KeygraphID
	NoteID     string `gorm:"type:varchar(255);primary_key"`
	Content    string `gorm:"type:text"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
	// Virtual
	Profile Profile `gorm:"foreignKey:KeygraphID;references:KeygraphID"`
}

type Profile

type Profile struct {
	KeygraphID  string `gorm:"type:varchar(255);primary_key"`
	DisplayName string
	Description string
	Alias       *nimona.IdentityAlias
	AvatarURL   string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
	// profile
	DisplayName string `json:"displayName"`
	Description string `json:"description"`
	AvatarURL   string `json:"avatarUrl"`
}

type RegisterResponse

type RegisterResponse struct {
	User       *User             `json:"user"`
	KeygraphID nimona.KeygraphID `json:"keygraph"`
	SessionID  string            `json:"sessionId"`
}

type SQLStore

type SQLStore struct {
	// contains filtered or unexported fields
}

func (*SQLStore) GetFollowees

func (s *SQLStore) GetFollowees(
	ctx context.Context,
	follower nimona.KeygraphID,
) ([]*Follow, error)

func (*SQLStore) GetFollowers

func (s *SQLStore) GetFollowers(
	ctx context.Context,
	followee nimona.KeygraphID,
) ([]*Follow, error)

func (*SQLStore) GetNotes

func (s *SQLStore) GetNotes(
	ctx context.Context,
	identityNRI string,

	offset int,
	limit int,
) ([]*Note, error)

func (*SQLStore) GetProfile

func (s *SQLStore) GetProfile(
	ctx context.Context,
	keygraphID nimona.KeygraphID,
) (*Profile, error)

func (*SQLStore) GetSession

func (s *SQLStore) GetSession(
	ctx context.Context,
	id string,
) (*Session, error)

func (*SQLStore) GetUser

func (s *SQLStore) GetUser(
	ctx context.Context,
	username string,
) (*User, error)

func (*SQLStore) PutFollow

func (s *SQLStore) PutFollow(
	ctx context.Context,
	req *Follow,
) error

func (*SQLStore) PutNote

func (s *SQLStore) PutNote(
	ctx context.Context,
	req *Note,
) error

func (*SQLStore) PutProfile

func (s *SQLStore) PutProfile(
	ctx context.Context,
	req *Profile,
) error

func (*SQLStore) PutSession

func (s *SQLStore) PutSession(
	ctx context.Context,
	req *Session,
) error

func (*SQLStore) PutUser

func (s *SQLStore) PutUser(
	ctx context.Context,
	req *User,
) error

PutUser will create or update a user

type Session

type Session struct {
	ID        string `gorm:"type:varchar(255);primary_key"`
	Username  string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Store

type Store interface {
	PutUser(context.Context, *User) error
	GetUser(context.Context, string) (*User, error)
	PutProfile(context.Context, *Profile) error
	GetProfile(context.Context, nimona.KeygraphID) (*Profile, error)
	PutNote(context.Context, *Note) error
	GetNotes(context.Context, string, int, int) ([]*Note, error)
	PutFollow(context.Context, *Follow) error
	GetFollowers(context.Context, nimona.KeygraphID) ([]*Follow, error)
	GetFollowees(context.Context, nimona.KeygraphID) ([]*Follow, error)
	PutSession(context.Context, *Session) error
	GetSession(context.Context, string) (*Session, error)
}

func NewSQLStore

func NewSQLStore(gdb *gorm.DB) Store

type TemplateValues

type TemplateValues struct {
	User  *User
	Error string
}

type UpdateProfileRequest

type UpdateProfileRequest struct {
	KeygraphID  nimona.KeygraphID     `json:"keygraph"`
	DisplayName string                `json:"displayName,omitempty"`
	Description string                `json:"description,omitempty"`
	AvatarURL   string                `json:"avatarUrl,omitempty"`
	Alias       *nimona.IdentityAlias `json:"alias,omitempty"`
}

type UpdateProfileResponse

type UpdateProfileResponse struct{}

type User

type User struct {
	KeygraphID   nimona.KeygraphID `gorm:"type:varchar(255);primary_key"`
	Username     string            `gorm:"type:varchar(255);unique,index"`
	Email        string            `gorm:"type:varchar(255);unique"`
	PasswordHash string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL