util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const BitLength = 8

Variables

This section is empty.

Functions

func BinaryBufferToBytes

func BinaryBufferToBytes(binBuffer *bytes.Buffer) ([]byte, error)

BinaryBufferToBytes turns the data from bytes.Buffer into a slice of bytes.

func BitToBool

func BitToBool(b byte) bool

BitToBool turns a bit into a bool.

func BoolToBit

func BoolToBit(b bool) byte

BoolToBit turns a bool into a bit.

func BoolToRune

func BoolToRune(b bool) rune

BoolToRune turns a bool into a rune.

func ByteArrToBits

func ByteArrToBits(byteArr []byte, resultChan chan byte)

ByteArrToBits turns given byteArr into bits and sends it over a channel.

func BytesToUint64

func BytesToUint64(bytes []byte) uint64

BytesToUint64 turns []byte to uint64.

func ClearBit

func ClearBit(n byte, pos byte) byte

ClearBit clears the bit at pos in n.

func EncodeNRGBA

func EncodeNRGBA(nrgba *image.NRGBA) (*bytes.Buffer, error)

EncodeNRGBA encodes given image.NRGBA into a bytes.Buffer.

func GenerateToken

func GenerateToken(
	ctx context.Context,
	entUser ent.User,
) (string, *time.Time, error)

GenerateToken created a jwt token and puts an ulid.ID into its claims.

func GetUpdatedByte

func GetUpdatedByte(newBit byte, value byte, lsbPos byte) byte

GetUpdatedByte updates value byte with newBit byte on lsbPos byte.

func HasBit

func HasBit(n byte, pos byte) bool

HasBit returns whether the byte n has a bit set on the pos.

func ImageToNRGBA

func ImageToNRGBA(img image.Image) (*image.NRGBA, int, int)

ImageToNRGBA converts image.Image to image.NRGBA.

func NewAuthorizationError

func NewAuthorizationError(
	ctx context.Context,
	message string,
) *gqlerror.Error

NewAuthorizationError returns a new gqlerror.Error with authorization ErrorCode.

func NewDBError

func NewDBError(
	ctx context.Context,
	message string,
) *gqlerror.Error

NewDBError returns a new gqlerror.Error with db ErrorCode.

func NewInternalServerError

func NewInternalServerError(
	ctx context.Context,
	message string,
) *gqlerror.Error

NewInternalServerError returns a new gqlerror.Error with internalServer ErrorCode.

func NewNotFoundError

func NewNotFoundError(
	ctx context.Context,
	message string,
) *gqlerror.Error

NewNotFoundError returns a new gqlerror.Error with notFound ErrorCode.

func NewValidationError

func NewValidationError(
	ctx context.Context,
	message string,
) *gqlerror.Error

NewValidationError returns a new gqlerror.Error with validation ErrorCode.

func ParseToken

func ParseToken(tokenStr string) (ulid.ID, error)

ParseToken parses a jwt token and returns the ulid.ID in its claims.

func ReadImageFile

func ReadImageFile(file io.Reader) (image.Image, error)

ReadImageFile reads given file and returns image.Image.

func SetBit

func SetBit(n byte, pos byte) byte

SetBit sets the bit at pos in the integer n.

func Trim

func Trim(src string, toTrim uint8) string

Trim trims src string with toTrim uint8.

func Uint64ToBytes

func Uint64ToBytes(num uint64) []byte

Uint64ToBytes turns int to []byte representing uint64.

Types

type Channel

type Channel string

Channel defines the type for the "channel" enum field.

const (
	ChannelRed          Channel = "RED"
	ChannelGreen        Channel = "GREEN"
	ChannelBlue         Channel = "BLUE"
	ChannelRedGreen     Channel = "RED_GREEN"
	ChannelRedBlue      Channel = "RED_BLUE"
	ChannelGreenBlue    Channel = "GREEN_BLUE"
	ChannelRedGreenBlue Channel = "RED_GREEN_BLUE"
)

Channel values.

func (Channel) Count

func (c Channel) Count() int

Count returns the number of color channels included in the Channel.

func (Channel) IncludesBlue

func (c Channel) IncludesBlue() bool

IncludesBlue returns whether the Channel includes Channel with blue value.

func (Channel) IncludesGreen

func (c Channel) IncludesGreen() bool

IncludesGreen returns whether the Channel includes Channel with green value.

func (Channel) IncludesRed

func (c Channel) IncludesRed() bool

IncludesRed returns whether the Channel includes Channel with red value.

func (Channel) String

func (c Channel) String() string

String returns a string representation of the Channel.

type ErrorCode

type ErrorCode string

ErrorCode represents an error code.

type ImageData

type ImageData struct {
	NRGBA  *image.NRGBA
	Width  int
	Height int
}

ImageData represents a data of an image.NRGBA and Width and Height.

func FileToImageData

func FileToImageData(file io.Reader) (ImageData, error)

FileToImageData reads file and returns ImageData.

func (ImageData) PixelCount

func (id ImageData) PixelCount() uint64

PixelCount returns the number of pixels of the image represented.

Jump to

Keyboard shortcuts

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