formater

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 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 Formater

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

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

func NewFormatter

func NewFormatter() *Formater

NewFormatter creates a new instance of Formater struct.

func (*Formater) FormatForFile

func (f *Formater) 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 (*Formater) FormatMessage

func (f *Formater) 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 JsonFormater

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

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

func NewJsonFormater

func NewJsonFormater() *JsonFormater

NewJsonFormater creates a new instance of JsonFormater and returns a pointer to it.

func (*JsonFormater) FormatForFile

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

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

func (*JsonFormater) FormatRequest

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

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

func (*JsonFormater) FormatResponse

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

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

type TextFormater

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

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

func NewTextFormater

func NewTextFormater() *TextFormater

NewTextFormater creates a new instance of TextFormater

func (*TextFormater) FormatForFile

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

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

func (*TextFormater) FormatRequest

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

FormatRequest formats the request data and returns it as a string

func (*TextFormater) FormatResponse

func (tf *TextFormater) 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