api

package
v0.0.0-...-056695e Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

Swagger

swag init -g api.go -o http/docs/

Documentation

Index

Constants

View Source
const (
	ECONFLICT       = "conflict"
	EINTERNAL       = "internal"
	EINVALID        = "invalid"
	ENOTFOUND       = "not_found"
	ENOTIMPLEMENTED = "not_implemented"
	EUNAUTHORIZED   = "unauthorized"
)

API error codes.

Variables

This section is empty.

Functions

func ErrorCode

func ErrorCode(err error) string

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".

Types

type Edge

type Edge struct {
	// UID is edge UUID.
	UID string `json:"uid,omitempty"`
	// Source is an ID of the edge source node.
	Source int64 `json:"source"`
	// Target is an ID of the edge target node.
	Target int64 `json:"target"`
	// Weight is the edge weight.
	Weight float64 `json:"weight"`
	// Label is edge label
	Label string `json:"label"`
	// Attrs are edge attributes
	Attrs map[string]interface{} `json:"attributes,omitempty"`
}

Edge is an edge between two graph nodes.

type EdgeFilter

type EdgeFilter struct {
	// Filtering fields.
	Source *int64  `json:"source"`
	Target *int64  `json:"target"`
	Label  *string `json:"label"`
	// Restrict to subset of range.
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

EdgeFilter represents a filter used by FindEdges().

type EdgeService

type EdgeService interface {
	// CreateEdge creates a new edge.
	CreateEdge(ctx context.Context, uid string, e *Edge) error
	// FindEdgeByUID returns a single edge with the given uid.
	FindEdgeByUID(ctx context.Context, guid, euid string) (*Edge, error)
	// FindEdges returns all edges matching the filter.
	// It also returns a count of total matching edges which may differ from
	// the number of returned edges if the Limit field is set.
	FindEdges(ctx context.Context, uid string, filter EdgeFilter) ([]*Edge, int, error)
	// UpdateEdgeBetween updates an edge between two nodes.
	UpdateEdgeBetween(ctx context.Context, uid string, source, target int64, update EdgeUpdate) (*Edge, error)
	// DeleteEdge permanently removes an edge by UID.
	DeleteEdge(ctx context.Context, guid, euid string) error
	// DeleteEdgeBetween permanently deletes all edges between two nodes.
	DeleteEdgeBetween(ctx context.Context, uid string, source, target int64) error
}

EdgeService represents a service for managing Edges.

type EdgeUpdate

type EdgeUpdate struct {
	Weight *float64               `json:"weight"`
	Label  *string                `json:"label"`
	Attrs  map[string]interface{} `json:"attributes,omitempty"`
}

EdgeUpdate represents a set of fields to update on an edge.

type Error

type Error struct {
	// Machine-readable error code.
	Code string
	// Human-readable error message.
	Message string
}

Error represents an application-specific error. Application errors can be unwrapped by the caller to extract out the code & message.

Any non-application error (such as a disk error) should be reported as an EINTERNAL error and the human user should only see "Internal error" as the message. These low-level internal error details should only be logged and reported to the operator of the application (not the end user).

func Errorf

func Errorf(code string, format string, args ...interface{}) *Error

Errorf is a helper function to return an Error with a given code and formatted message.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

type Graph

type Graph struct {
	// UID is graph UUID.
	UID string `json:"uid,omitempty"`
	// Type is a type of graph.
	Type string `json:"type,omitempty"`
	// Nodes is the node count.
	Nodes int `json:"nodes"`
	// Edge is the edge count.
	Edges int `json:"edges"`
	// Label is graph label.
	Label string `json:"label,omitempty"`
	// Attrs are graph attributes.
	Attrs map[string]interface{} `json:"attributes,omitempty"`
}

Graph contains nodes connected by edges.

type GraphFilter

type GraphFilter struct {
	// Filtering fields.
	UID   *string `json:"uid"`
	Type  *string `json:"type"`
	Label *string `json:"label"`
	// Restrict to subset of range.
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

GraphFilter represents a filter used by FindGraphs().

type GraphService

type GraphService interface {
	// CreateGraph creates a new graph.
	CreateGraph(ctx context.Context, g *Graph) error
	// FindGraphByUID returns a single graph with the given uid.
	FindGraphByUID(ctx context.Context, uid string) (*Graph, error)
	// FindGraphs returns all graphs matching the filter.
	// It also returns a count of total matching graphs which may differ from
	// the number of returned graphs if the Limit field is set.
	FindGraphs(ctx context.Context, filter GraphFilter) ([]*Graph, int, error)
	// UpdateGraph updates an existing graph by UID.
	UpdateGraph(ctx context.Context, uid string, update GraphUpdate) (*Graph, error)
	// DeleteGraph permanently removes a graph by UID.
	DeleteGraph(ctx context.Context, uid string) error
}

GraphService represents a service for managing Graphs.

type GraphUpdate

type GraphUpdate struct {
	Label *string                `json:"label"`
	Attrs map[string]interface{} `json:"attributes,omitempty"`
}

GraphUpdate represents a set of fields to update on a graph.

type Node

type Node struct {
	// ID is node ID.
	ID int64 `json:"id"`
	// UID is node UUID.
	UID string `json:"uid,omitempty"`
	// DegOut is the count of outgoing edges.
	DegOut int `json:"deg_out"`
	// DegIn is the count of incoming edges.
	DegIn int `json:"deg_in"`
	// Label is node label
	Label string `json:"label"`
	// Attrs are node attributes
	Attrs map[string]interface{} `json:"attributes,omitempty"`
}

Node is a graph node.

type NodeFilter

type NodeFilter struct {
	// Filtering fields.
	ID    *int64  `json:"id"`
	To    *int64  `json:"to"`
	From  *int64  `json:"from"`
	UID   *string `json:"uid"`
	Label *string `json:"label"`
	// Restrict to subset of range.
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

NodeFilter represents a filter used by FindNodes().

type NodeService

type NodeService interface {
	// FindNodeByID returns a single node with the given id.
	FindNodeByID(ctx context.Context, uid string, id int64) (*Node, error)
	// FindNodeByUID returns a single node with the given uid.
	FindNodeByUID(ctx context.Context, guid, nuid string) (*Node, error)
	// FindNodes returns all nodes matching the filter.
	// It also returns a count of total matching nodes which may differ from
	// the number of returned nodes if the Limit field is set.
	FindNodes(ctx context.Context, uid string, filter NodeFilter) ([]*Node, int, error)
	// CreateNode creates a new node.
	CreateNode(ctx context.Context, uid string, n *Node) error
	// UpdateNode updates an existing node by ID.
	UpdateNode(ctx context.Context, uid string, id int64, update NodeUpdate) (*Node, error)
	// DeleteNodeByUID permanently removes a node by UID.
	// It automatically removes removed node's incoming and outgoing edges.
	DeleteNodeByUID(ctx context.Context, guid, nuid string) error
	// DeleteNodeByID permanently removes a node by ID.
	// It automatically removes removed node's incoming and outgoing edges.
	DeleteNodeByID(ctx context.Context, uid string, id int64) error
}

NodeService represents a service for managing graph nodes.

type NodeUpdate

type NodeUpdate struct {
	Label *string                `json:"label"`
	Attrs map[string]interface{} `json:"attributes,omitempty"`
}

NodeUpdate represents a set of fields to update on a node.

Directories

Path Synopsis
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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