goutils

package module
v0.0.0-...-9d149b6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

gotils

WARNING: This repo not intended for public use and has no versioning applied. So be warned: things can break between commits.

goutils is a collection of random bits & pieces I've been using across projects.

Development

This codebase contains a combination of integration and unit tests.

To run all of them in a human-readable way use:

$ make humantest

This requires richgo to be installed.

See the project's Makefile for other (more standard) commands.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(log zerolog.Logger, c io.Closer)

Close is a simple utility used to log error messages riased during a deferred closing function. For example:

defer utils.Close(myLog, f)

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It returns an error if the system's secure random number generator fails.

func GenerateRandomString

func GenerateRandomString(bytes int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded random string.

It returns an error if the system's secure random number generator fails.

func GenerateShortID

func GenerateShortID() string

GenerateShortID returns a base58-encoded UUID which is 22 characters long.

Types

type AssertJSON

type AssertJSON struct {
	T    *testing.T
	Body []byte
}

func NewAssertJSON

func NewAssertJSON(t *testing.T, body []byte) *AssertJSON

func (*AssertJSON) Equal

func (a *AssertJSON) Equal(path string, expected interface{}, msgAndArgs ...interface{})

func (*AssertJSON) False

func (a *AssertJSON) False(path string, msgAndArgs ...interface{})

func (*AssertJSON) Len

func (a *AssertJSON) Len(path string, length int, msgAndArgs ...interface{})

func (*AssertJSON) Nil

func (a *AssertJSON) Nil(path string, msgAndArgs ...interface{})

func (*AssertJSON) Raw

func (a *AssertJSON) Raw(path string, expected interface{}, msgAndArgs ...interface{})

func (*AssertJSON) Regexp

func (a *AssertJSON) Regexp(path string, rx interface{}, msgAndArgs ...interface{})

func (*AssertJSON) TimeBetween

func (a *AssertJSON) TimeBetween(path string, minDur time.Duration, maxDur time.Duration, msgAndArgs ...interface{})

func (*AssertJSON) True

func (a *AssertJSON) True(path string, msgAndArgs ...interface{})

type Loader

type Loader struct {
	Dir         string
	LayoutsDir  string
	PartialsDir string
	Suffix      string
}

Loader loads layout, partial and template files from a specified directory.

Dealing with partials and layouts in template files is notoriously tricky using the standard Golang template parser. This Loader makes is easier to simply load a template by name and parse one of the blocks within that template file.

func NewTemplateLoader

func NewTemplateLoader(dir string) *Loader

NewTemplateLoader creates a Loader with the recommended layouts directory "/layouts" and partials directory "/partials". These directories are relative from the specified template directory.

func (*Loader) LoadAllTemplates

func (t *Loader) LoadAllTemplates() (map[string]*template.Template, error)

LoadAllTemplates creates separate templates for each template in the template directory.

func (*Loader) LoadTemplate

func (t *Loader) LoadTemplate(templateName string) (*template.Template, error)

LoadTemplate loads a single template file and any partials and layout templates from the template directory.

type TestLogger

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

func (*TestLogger) LastLine

func (log *TestLogger) LastLine() (result map[string]interface{})

func (*TestLogger) Lines

func (log *TestLogger) Lines() (result []map[string]interface{})

func (*TestLogger) Write

func (log *TestLogger) Write(p []byte) (n int, err error)

Directories

Path Synopsis
Package validator implements value validations Copyright 2014 Roberto Teixeira <robteix@robteix.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
Package validator implements value validations Copyright 2014 Roberto Teixeira <robteix@robteix.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

Jump to

Keyboard shortcuts

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