note

package
v0.0.0-...-8fbb377 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

* Copyright (c) 2020. Denis Rendler <connect@rendler.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright (c) 2020. Denis Rendler <connect@rendler.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright (c) 2020. Denis Rendler <connect@rendler.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright (c) 2020. Denis Rendler <connect@rendler.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	StoredTemplate  = "new_note.gohtml"
	FetchedTemplate = "note_read.gohtml"
)
View Source
const (
	StoreEvent = "new_note"
	FetchEvent = "note_read"
)
View Source
const (
	ExpireOnRead    = "on-read"
	ExpireAfter5M   = "5m"
	ExpireAfter30M  = "30m"
	ExpireAfter1H   = "1h"
	ExpireAfter1DAY = "24h"
	ExpireAfter2DAY = "48h"
	ExpireAfter7DAY = "168h"
)

Variables

View Source
var ErrNotFound = errors.New("note not found")

Functions

func InitSketch

func InitSketch(c sketch.Config) error

func RegisterSubscribers

func RegisterSubscribers(broker events.Broker)

RegisterSubscribers

Types

type ContentMessage

type ContentMessage struct {
	Status  bool   `json:"complete"`
	Content string `json:"content"`
}

ContentMessage is an API representation of note content stored

type InputMessage

type InputMessage struct {
	Content    string       `json:"content" validate:"required,min=1"`
	AutoExpire string       `json:"auto-expire,omitempty" validate:"omitempty,expire-interval"`
	Notify     Notification `json:"notify,omitempty"`
}

InputMessage is an API representation of incoming note data and options

func (*InputMessage) IsAutoExpire

func (in *InputMessage) IsAutoExpire() bool

func (*InputMessage) IsValid

func (in *InputMessage) IsValid() (bool, []string)

InputMessage.IsValid is used to validate data passed from the client

type LinkMessage

type LinkMessage struct {
	Status bool   `json:"complete"`
	Id     string `json:"note-id"`
}

LinkMessage is an API representation of successful storage of note and options

type MemoryRepo

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

func NewMemoryRepo

func NewMemoryRepo() *MemoryRepo

func (MemoryRepo) FetchByID

func (s MemoryRepo) FetchByID(id string) (*Note, error)

FetchByID retrieves a note based on it's ID

func (*MemoryRepo) Pop

func (s *MemoryRepo) Pop(id string) (*Note, error)

Pop is used to retrieve a note and remove it from the collection at the same time

func (*MemoryRepo) Store

func (s *MemoryRepo) Store(note *Note) (*Note, error)

Store retrieves a note based on it's ID

func (*MemoryRepo) StoreWithTimeout

func (s *MemoryRepo) StoreWithTimeout(note *Note, until string) (*Note, error)

type Note

type Note struct {
	ID      uuid.UUID
	Content string
	Date    time.Time
	Notify  Notification
}

Note type used for defining a note

func NewNote

func NewNote(opts ...NoteOptions) *Note

type NoteEvent

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

func NewFetchedEvent

func NewFetchedEvent(note Note) *NoteEvent

func NewStoredEvent

func NewStoredEvent(note Note) *NoteEvent

func (NoteEvent) GetName

func (n NoteEvent) GetName() string

func (NoteEvent) GetPayload

func (n NoteEvent) GetPayload() interface{}

type NoteOptions

type NoteOptions func(*Note)

func FromInput

func FromInput(input InputMessage) NoteOptions

type Notification

type Notification struct {
	Recipient string
	Sender    string
}

type Repository

type Repository interface {
	FetchByID(string) (*Note, error)
	Pop(string) (*Note, error)
	Store(*Note) (*Note, error)
	StoreWithTimeout(*Note, string) (*Note, error)
}

type WebApi

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

NotesWebApi controller

func NewWebApi

func NewWebApi(repository Repository, evStream ev.Broker) *WebApi

NewWebApi initialize a new controller

func NewWithMemoryRepo

func NewWithMemoryRepo() *WebApi

@deprecated

func (WebApi) RegisterRoutes

func (nc WebApi) RegisterRoutes(r *mux.Router)

RegisterRoutes the Notes api endpoints

func (WebApi) Retrieve

func (nc WebApi) Retrieve(w http.ResponseWriter, r *http.Request)

Retrieve controller to get the secret note

func (WebApi) Store

func (nc WebApi) Store(w http.ResponseWriter, r *http.Request)

Store controller to save into memory the secret note

Jump to

Keyboard shortcuts

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