ray

package module
v0.0.0-...-a84e73c Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 13 Imported by: 0

README

Ray codecov

This package can be used to send messages to the Ray app or buggregator.

Usage

All functions are applicable to the ray.RayEntry object or directly to the package (ray.Caller()). In this case the ray.DefaultClient is used.

package main

import (
    ray "github.com/pkuebler/go-ray"
)

func main() {
    // default object
    ray.Ray("my message")

    // own entry
	entry := ray.NewRayEntry(ray.DefaultClient, "")
	entry.TypeName(int64(4343))

    // own client inside a docker container
    client := ray.NewRayClient("host.docker.internal", 23517)
	entry := ray.NewRayEntry(client, "")
    
    // reuse ray entry (settings)
    greenMessages := ray.WithColor("green")
    greenMessages.Ray("my message")

    // change setting on current
    greenMessages.SetColor("red")

    // trigger system notification
    greenMessages.Notify("hi")

    // dump request
	req, err := http.NewRequest("POST", "/health-check", strings.NewReader("{\"fieldA\": 234}"))
	if err != nil {
        panic(err)
	}
	ray.Request(req)

    // dump response
    resp, err := http.Get("http://localhost:8080")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
	ray.Reader(resp.Body)
}

Size / Sort

Messages can be assigned to a color to group them.

// set on current entry object
greenMessages.SetColor("red")
greenMessages.SetSize("lg")

// get a new entry object
redMessages := greenMessages.WithColor("red")
redMessages := greenMessages.WithSize("lg")

Chainable

All functions return a ray.Entry object and can be concatenated.

// set on current entry object
greenMessages.SetColor("red").Ray("my notice").TypeName(int64(334))

Docker

In a Docker container, host.docker.internal must be defined as the host.

License

The MIT License (MIT). Please see License File for more information.

ToDo:

  • add tests
  • message color as definition
  • message size as definition
  • waitgroup go routines to send
  • move disabled more to front
  • move payload code from ray to payloads

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultClient to ray app
	DefaultClient *RayClient = NewRayClient("localhost", 23517)
	// DefaultRayEntry with current settings
	DefaultRayEntry *RayEntry = NewRayEntry(DefaultClient, "")
)

Functions

This section is empty.

Types

type Message

type Message struct {
	UUID     string                   `json:"uuid"`
	Payloads []map[string]interface{} `json:"payloads"`
	Meta     map[string]string        `json:"meta"`
}

Message to communicate with the ray app

type RayClient

type RayClient struct {
	Enabled bool   `json:"enable"`
	Host    string `json:"host"`
	Port    int    `json:"port"`
}

RayClient contains the configuration to Ray App

func NewRayClient

func NewRayClient(host string, port int) *RayClient

NewRayClient create a client

func (*RayClient) Send

func (r *RayClient) Send(msg Message)

Send to ray app

type RayEntry

type RayEntry struct {
	Client *RayClient

	// Color that can be used are green, orange, red, blue, purple and gray. An
	// empty string removes the color.
	Color string

	// Size that can be used are sm, lg or an empty string.
	Size string

	// UUID of the last message
	UUID string
}

RayEntry is the final or intermediate ray entry. It contains color, size and the final uuid. These objects can be reused to avoid having to redefine font size or color.

func Caller

func Caller() *RayEntry

Caller sends the current position in the code to Ray.

func Charles

func Charles() *RayEntry

Charles print icons at Ray

func ClearScreen

func ClearScreen() *RayEntry

ClearScreen creates a new screen with empty entry list.

func Custom

func Custom(content string, label string) *RayEntry

Custom message with content and an optional label in Ray.

func DumpStruct

func DumpStruct(obj interface{}) *RayEntry

DumpStruct print the struct at ray. Requires a pointer.

func JSON

func JSON(obj interface{}) *RayEntry

JSON convert and send a interface to json string

func JSONString

func JSONString(jsonString string) *RayEntry

JSONString send a string with json as json string

func NewRayEntry

func NewRayEntry(client *RayClient, id string) *RayEntry

NewRayEntry creates a new RayEntry with default settings. If the UUID is empty, a new one is generated. The UUID is overwritten with each new message.

func NewScreen

func NewScreen(screenName string) *RayEntry

NewScreen creates a new screen with optional name. All following entries will be displayed on this screen.

func Notify

func Notify(text string) *RayEntry

Notify triggers a system notification about Ray.

func Ray

func Ray(objs ...interface{}) *RayEntry

Ray send parameters to ray

func Reader

func Reader(reader io.Reader) *RayEntry

Reader dump e.g. request response body

func Request

func Request(req *http.Request) *RayEntry

Request dump a golang request at Ray

func SetColor

func SetColor(color string) *RayEntry

SetColor sets the color of the default RayEntry.

func SetSize

func SetSize(size string) *RayEntry

SetSize sets the size of the default RayEntry.

func Trace

func Trace() *RayEntry

Trace sent the trace as custom message to Ray. Unfortunately, Ray's trace message is not easy to fill with the go trace.

func TypeName

func TypeName(obj interface{}) *RayEntry

TypeName send the type name to ray as custom message

func (*RayEntry) Caller

func (r *RayEntry) Caller() *RayEntry

Caller sends the current position in the code to Ray.

func (*RayEntry) Charles

func (r *RayEntry) Charles() *RayEntry

Charles print icons at Ray

func (*RayEntry) ClearScreen

func (r *RayEntry) ClearScreen() *RayEntry

ClearScreen creates a new screen with empty entry list.

func (*RayEntry) Clone

func (r *RayEntry) Clone() *RayEntry

Clone RayEntry

func (*RayEntry) Custom

func (r *RayEntry) Custom(content string, label string) *RayEntry

Custom message with content and an optional label in Ray.

func (*RayEntry) DumpStruct

func (r *RayEntry) DumpStruct(obj interface{}) *RayEntry

DumpStruct print the struct at ray. Requires a pointer.

func (*RayEntry) Hide

func (r *RayEntry) Hide() *RayEntry

Hide xxx

func (*RayEntry) JSON

func (r *RayEntry) JSON(obj interface{}) *RayEntry

JSON convert and send a interface to json string

func (*RayEntry) JSONString

func (r *RayEntry) JSONString(jsonString string) *RayEntry

JSONString send a string with json as json string

func (*RayEntry) NewScreen

func (r *RayEntry) NewScreen(name string) *RayEntry

NewScreen creates a new screen with optional name. All following entries will be displayed on this screen.

func (*RayEntry) Notify

func (r *RayEntry) Notify(text string) *RayEntry

Notify triggers a system notification about Ray.

func (*RayEntry) Ray

func (r *RayEntry) Ray(obj ...interface{}) *RayEntry

Ray send parameters to ray

func (*RayEntry) Reader

func (r *RayEntry) Reader(reader io.Reader) *RayEntry

Reader dump e.g. request response body

func (*RayEntry) Remove

func (r *RayEntry) Remove() *RayEntry

Remove xxx

func (*RayEntry) Request

func (r *RayEntry) Request(req *http.Request) *RayEntry

Request dump a golang request at Ray

func (*RayEntry) SetColor

func (r *RayEntry) SetColor(color string) *RayEntry

SetColor sets the color of the current RayEntry.

func (*RayEntry) SetSize

func (r *RayEntry) SetSize(size string) *RayEntry

SetSize sets the size of the current RayEntry.

func (*RayEntry) Trace

func (r *RayEntry) Trace() *RayEntry

Trace sent the trace as custom message to Ray. Unfortunately, Ray's trace message is not easy to fill with the go trace.

func (*RayEntry) TypeName

func (r *RayEntry) TypeName(obj interface{}) *RayEntry

TypeName send the type name to ray as custom message

func (*RayEntry) WithColor

func (r *RayEntry) WithColor(color string) *RayEntry

WithColor creates a new RayEntry with the passed color.

func (*RayEntry) WithSize

func (r *RayEntry) WithSize(size string) *RayEntry

WithSize creates a new RayEntry with the passed size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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