toolkit

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

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 7 Imported by: 0

README

Tool

A simple example of how to create a reusable Go module with commonly used tools.

The included tools are:

  • Read JSON
  • Write JSON
  • Produce a JSON encoded error response
  • Upload a file to a specified directory
  • Download a static file
  • Get a random string of length n
  • Post JSON to a remote service
  • Create a directory, including all parent directories, if it does not already exist
  • Create a URL safe slug from a string

Installation

go get -u github.com/tsawler/toolkit

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tools

type Tools struct {
	MaxFileSize      int
	AllowedFileTypes []string
}

func (*Tools) CreateDirIfNotExist

func (t *Tools) CreateDirIfNotExist(path string) error

func (*Tools) RandomString

func (t *Tools) RandomString(length int) string

func (*Tools) UploadFile

func (t *Tools) UploadFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)

func (*Tools) UploadFiles

func (t *Tools) UploadFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)

type UploadedFile

type UploadedFile struct {
	NewFileName      string
	OriginalFileName string
	FileSize         int64
}

Jump to

Keyboard shortcuts

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