api

package
v1.0.609 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 17

Documentation

Index

Constants

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

Application error codes.

These are meant to be generic and they map well to HTTP error codes.

Variables

View Source
var DefaultConfig = Config{
	Postgrest: PostgrestConfig{
		Version:   "v10.0.0",
		DBRole:    "postgrest_api",
		Port:      3000,
		AdminPort: 3001,
		MaxRows:   2000,
	},
}

Functions

func ErrorCode

func ErrorCode(err error) string

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

func ErrorData added in v1.0.428

func ErrorData(err error) string

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

func ErrorDebugInfo

func ErrorDebugInfo(err error) string

ErrorDebugInfo unwraps an application error and returns its debug message.

func ErrorMessage

func ErrorMessage(err error) string

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

func ErrorStatusCode

func ErrorStatusCode(code string) int

ErrorStatusCode returns the associated HTTP status code for an application error code.

func PrintableSecret added in v1.0.574

func PrintableSecret(secret string) string

func WriteError

func WriteError(c echo.Context, err error) error

func WriteSuccess added in v1.0.510

func WriteSuccess(c echo.Context, payload any) error

Types

type Config added in v1.0.564

type Config struct {
	Metrics                  bool
	ConnectionString, Schema string
	DisableKubernetes        bool
	Namespace                string
	Postgrest                PostgrestConfig
	LogLevel                 string
	LogName                  string

	RunMigrations      bool
	SkipMigrations     bool
	SkipMigrationFiles []string
	MigrationMode      MigrationMode
}

func NewConfig added in v1.0.576

func NewConfig(connection string) Config

func (Config) GetUsername added in v1.0.576

func (c Config) GetUsername() string

func (*Config) Migrate added in v1.0.581

func (t *Config) Migrate() bool

func (Config) ReadEnv added in v1.0.574

func (c Config) ReadEnv() Config

func (Config) String added in v1.0.574

func (c Config) String() string

type Error

type Error struct {
	// Machine-readable error code.
	Code string

	// Human-readable error message.
	Message string

	// Machine-machine error message.
	Data string

	// DebugInfo contains low-level internal error details that should only be logged.
	// End-users should never see this.
	DebugInfo string
}

Error represents an application-specific error.

func Errorf

func Errorf(code string, format string, args ...any) *Error

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

func FromError added in v1.0.428

func FromError(err error) *Error

func (*Error) Error

func (e *Error) Error() string

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

func (*Error) WithData added in v1.0.428

func (e *Error) WithData(data any) *Error

WithData sets the given data

func (*Error) WithDebugInfo

func (e *Error) WithDebugInfo(msg string, args ...any) *Error

WithDebugInfo wraps an application error with a debug message.

type HTTPError

type HTTPError struct {
	Err     string `json:"error"`
	Message string `json:"message,omitempty"`

	// Data for machine-machine communication.
	// usually contains a JSON data.
	Data string `json:"data,omitempty"`
}

func HTTPErrorFromErr added in v1.0.494

func HTTPErrorFromErr(err error) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

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

type HTTPSuccess

type HTTPSuccess struct {
	Message string `json:"message"`
	Payload any    `json:"payload,omitempty"`
}

type MigrationMode added in v1.0.581

type MigrationMode int
const (
	RunByDefault MigrationMode = iota
	SkipByDefault
)

type PostgrestConfig added in v1.0.564

type PostgrestConfig struct {
	Port      int
	Disable   bool
	LogLevel  string
	URL       string
	Version   string
	JWTSecret string
	DBRole    string
	AdminPort int

	// A hard limit to the number of rows PostgREST will fetch from a view, table, or stored procedure.
	// Limits payload size for accidental or malicious requests.
	MaxRows int
}

func (PostgrestConfig) ReadEnv added in v1.0.574

func (p PostgrestConfig) ReadEnv() PostgrestConfig

func (PostgrestConfig) String added in v1.0.574

func (p PostgrestConfig) String() string

Jump to

Keyboard shortcuts

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