state

package
v0.0.0-...-c186bf4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppState

type AppState struct {
	Focused      tview.Primitive
	LastError    error `json:"-"` // do not serialize
	Collection   *CollectionItem
	SelectedItem *CollectionItem
	ActiveItem   *CollectionItem
}

AppState represents the state of the application.

func DeserializeAppState

func DeserializeAppState(data []byte) (*AppState, error)

DeserializeAppState returns an AppState from data.

func NewAppState

func NewAppState() *AppState

NewAppState returns a new AppState instance.

func (*AppState) EnsureDefaultItems

func (a *AppState) EnsureDefaultItems()

EnsureDefaultItems ensures that both the active and selected item are not nil. If either is nil, they will be set to the first non-group CollectionItem in the collection.

func (*AppState) FirstCollectionItem

func (a *AppState) FirstCollectionItem(filter func(item *CollectionItem) bool) *CollectionItem

FirstCollectionItem returns the first CollectionItem that satisfies the filter predicate.

func (*AppState) RemoveCollectionItem

func (a *AppState) RemoveCollectionItem(item *CollectionItem)

RemoveCollectionItem removes the given item from the collection. If the removed item was currently active or selected, then the active and/or selected item will be set to nil. It is the responsibility of the caller to reestablish the active and selected item after the fact.

func (*AppState) Serialize

func (a *AppState) Serialize() ([]byte, error)

Serialize returns the bytes representing the app state.

type CollectionItem

type CollectionItem struct {
	UUID           uuid.UUID
	IsGroup        bool
	Name           string
	Method         string
	URL            string
	Headers        map[string][]string
	RequestBody    *RequestBody
	Authentication ItemAuthentication
	Result         *HTTPResult     `json:"-"` // do not serialize
	Parent         *CollectionItem `json:"-"` // prepare circular references when serializing
	Children       []*CollectionItem
}

CollectionItem is a grouping or a single, saved REST API request with a given name.

func NewCollectionGroup

func NewCollectionGroup(name string, parent *CollectionItem) *CollectionItem

NewCollectionGroup returns a CollectionGroup with a given name and no children. An optional parent may be provided to make this group a child of that item.

func NewCollectionRequest

func NewCollectionRequest(name, method string, url string, parent *CollectionItem) *CollectionItem

NewCollectionRequest returns a CollectionRequest representing a REST API request. An optional parent may be provided // to make this item a child of that item.

func (*CollectionItem) AddChild

func (c *CollectionItem) AddChild(item *CollectionItem)

AddChild appends an item to the end of this item's children. If this item is not a group (isGroup is false), then this method does nothing.

func (*CollectionItem) AddHeader

func (c *CollectionItem) AddHeader(key string, value string)

AddHeader adds a header with the given key and value.

func (*CollectionItem) AddHeaders

func (c *CollectionItem) AddHeaders(key string, values []string)

AddHeaders adds headers with the given key and values.

func (*CollectionItem) Ancestors

func (c *CollectionItem) Ancestors() []*CollectionItem

Ancestors returns the collection items that form a path to this item. The list will be ordered by most distant to most recent ancestor, with the current item being the last element in the list.

func (*CollectionItem) InsertChildAfter

func (c *CollectionItem) InsertChildAfter(item *CollectionItem, after *CollectionItem)

InsertChildAfter inserts an item after the given child item. If this item is not a group (isGroup is false), then this method does nothing.

func (*CollectionItem) IsDescendentOf

func (c *CollectionItem) IsDescendentOf(item *CollectionItem) bool

IsDescendentOf returns true if this item is a descendent of the given item.

func (*CollectionItem) RemoveChild

func (c *CollectionItem) RemoveChild(item *CollectionItem) error

RemoveChild removes the given item from the list of children of this item. If the item cannot be removed, an error will be returned.

func (*CollectionItem) RemoveHeader

func (c *CollectionItem) RemoveHeader(key string)

RemoveHeader removes a header with the given key and value.

type HTTPResult

type HTTPResult struct {
	Response     *http.Response
	Payload      []byte
	PayloadError error
	Duration     time.Duration
}

HTTPResult stores a http.Response and its associated metadata for a collection item.

type ItemAuthentication

type ItemAuthentication struct {
	Data auth.RequestAuthentication
}

ItemAuthentication is a container for authentication parameters for a collection item.

func (*ItemAuthentication) MarshalJSON

func (i *ItemAuthentication) MarshalJSON() ([]byte, error)

func (*ItemAuthentication) None

func (i *ItemAuthentication) None() bool

func (*ItemAuthentication) UnmarshalJSON

func (i *ItemAuthentication) UnmarshalJSON(b []byte) error

type Manager

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

Manager provides maintenance and lifecycle handling for AppState changes.

func NewStateManager

func NewStateManager(state *AppState, savePath string) *Manager

NewStateManager returns an instance of Manager that handles an instance of AppState.

func (*Manager) Get

func (m *Manager) Get() *AppState

Get returns the AppState handled by this Manager.

func (*Manager) SetDirty

func (m *Manager) SetDirty()

SetDirty flags that the current app state has changed and should be saved to disk.

func (*Manager) Shutdown

func (m *Manager) Shutdown() error

Shutdown flushes any pending state updates to disk.

type RequestBody

type RequestBody struct {
	Payload     string
	ContentType string
}

RequestBody stores the request body and associated content information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳