formater

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format added in v0.3.1

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

Format is a struct that contains two formatters, one for text and one for JSON.

func NewFormat added in v0.3.1

func NewFormat() *Format

NewFormat creates a new instance of Format struct.

func (*Format) FormatForFile added in v0.3.1

func (f *Format) FormatForFile(wsMsg ws.Message) (string, error)

FormatForFile formats the given WebSocket message for a file. It first tries to parse the message data as JSON, and if successful, formats it as JSON. If parsing fails, it formats the message data as plain text.

func (*Format) FormatMessage added in v0.3.1

func (f *Format) FormatMessage(wsMsg ws.Message) (string, error)

FormatMessage formats the given WebSocket message based on its type and data. If the data is a valid JSON, it will be formatted using the JSON formatter. Otherwise, it will be formatted using the text formatter.

type Formater

type Formater interface {
	FormatMessage(wsMsg ws.Message) (string, error)
	FormatForFile(wsMsg ws.Message) (string, error)
}

type JSONFormat added in v0.3.1

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

JSONFormat is a struct that contains two colorjson formatters for request and response.

func NewJSONFormat added in v0.3.1

func NewJSONFormat() *JSONFormat

NewJSONFormat creates a new instance of JSONFormat and returns a pointer to it.

func (*JSONFormat) FormatForFile added in v0.3.1

func (jf *JSONFormat) FormatForFile(data any) (string, error)

FormatForFile formats the given data as a JSON string using the default json package.

func (*JSONFormat) FormatRequest added in v0.3.1

func (jf *JSONFormat) FormatRequest(data any) (string, error)

FormatRequest formats the given data as a JSON string using the request formatter.

func (*JSONFormat) FormatResponse added in v0.3.1

func (jf *JSONFormat) FormatResponse(data any) (string, error)

FormatResponse formats the given data as a JSON string using the response formatter.

type TextFormat added in v0.3.1

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

TextFormat is a struct that holds the color for request and response

func NewTextFormat added in v0.3.1

func NewTextFormat() *TextFormat

NewTextFormat creates a new instance of TextFormat

func (*TextFormat) FormatForFile added in v0.3.1

func (tf *TextFormat) FormatForFile(data string) (string, error)

FormatForFile formats the data for file and returns it as a string

func (*TextFormat) FormatRequest added in v0.3.1

func (tf *TextFormat) FormatRequest(data string) (string, error)

FormatRequest formats the request data and returns it as a string

func (*TextFormat) FormatResponse added in v0.3.1

func (tf *TextFormat) FormatResponse(data string) (string, error)

FormatResponse formats the response data and returns it as a string

Jump to

Keyboard shortcuts

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