preserves

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 13 Imported by: 0

README

Preserves

These are preparations of canned code for all occasions. Might come in handy sometime.
GoDoc Go Report Card GitHub gocover.io Coverage

This repository is under development.

Detailed description

In any business, every master has a set of good tools, and coders have their own tools too.
There are two large categories of tools: the first one we use constantly, every day and they wander from one project to another, and the second type of tools we use rarely, in cases of emergency.
All these tools are well-established and tested, they are fast, efficient and safe.
I decided to build my own box of tool code so that the code would be available at all times.

You can quickly connect all the tools from this set

go get github.com/Kwynto/preserves

In your Go code, connect the blanks like this:

import "github.com/Kwynto/preserves"

When you stop using this package, do not forget to get rid of unnecessary dependencies in your project

go mod tidy

This package does not require separate documentation, as it is a collection of various powerful functions and each function has a description.

If you want to increase the efficiency of your code, then you will need to take individual functions and copy them into your project.
To do this, you will need to first copy the entire repository to yourself.

git clone https://github.com/Kwynto/preserves.git

This package has two files ordinary.go for commonly used functions and curiosity.go for functions that are rarely needed.

You can also contribute to this repository through a pull request and this toolbox will be our shared one.
If you want to add your own function to the repository, don't forget to write a test and a benchmark.
You can create your own file, for example <your_name>.go and <your_name>_test.go for testing (benchmarking).
Whatever the name of your file, the package must have the title package preserves.

Check out the documentation

Look at the documentation in two steps.
First, in the console, run:

godoc -http=:8080

And then in your web browser navigate to the uri:

http://localhost:8080

The godoc utility may not be present in your Go build and you may need to install it
command go get -v golang.org/x/tools/cmd/godoc

You can also use Go's standard functionality to view documentation in the console via go doc.
For example:

go doc GenerateId

If your IDE is good enough, then the documentation for functions and methods will be available from your code editor.

Testing

Run tests:

go test -v

Run tests showing code coverage:

go test -cover -v

You can view code coverage in detail in your web browser.
To do this, you need to sequentially execute two commands in the console:

go test -coverprofile="coverage.out" -v
go tool cover -html="coverage.out"

Performance

You can look at code performance tests:

go test -benchmem -bench="." curiosity.go curiosity_test.go

or

go test -benchmem -bench="." ordinary.go ordinary_test.go

⬆ back to top

About the author

The author of the project is Constantine Zavezeon (Kwynto).
You can contact the author by e-mail: kwynto@mail.ru
The author accepts proposals for participation in open source projects,
as well as willing to accept job offers.

⬆ back to top

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatBuffer

func ConcatBuffer(vals ...string) string

The ConcatBuffer() function quickly concatenates strings. This feature is useful for optimizing code that needs to quickly concatenate strings.

func ConcatCopy

func ConcatCopy(len int, vals ...string) string

The ConcatCopy() function is a very fast string concatenation, but requires knowing the length of the string, since anything over that length will be lost. This feature is useful for optimizing code that needs to quickly concatenate strings.

func DeleteCookie

func DeleteCookie(w *http.ResponseWriter, cookieName string)

The DeleteCookie(w) function deletes the cookie

func DownloadFile added in v0.0.2

func DownloadFile(sourceUrl string, dstFolder string) (string, error)

The DownloadFile() function downloads a file from a remote host and writes it to the specified folder, the function returns the file name.

func Fibo

func Fibo(n uint) uint

The Fibo() function is a fast implementation of the Fibonacci number via finite recursion.

func FindEmail

func FindEmail(input string) (string, error)

The FindEmail() function looks for an email address in a string and returns it or an error.

func GenerateId

func GenerateId() string

The GenerateId() generates a new id in a random, cryptographically secure manner

func MeanValue

func MeanValue(x []float64) float64

The MeanValue() function returns the average value from a slice of real numbers.

func MedianValue

func MedianValue(x []float64) float64

The MedianValue() function returns the median value of a slice of real numbers.

func PerformanceTest

func PerformanceTest() int

The PerformanceTest() function measures the amount of time the current time is added to the slice in 3 seconds. This feature can be used to evaluate the performance of your computer.

func RandInt

func RandInt(min, max int64) int64

The RandInt() function generates a real random integer.

func Variance

func Variance(x []float64) float64

The Variance() function returns the variance from a slice of real numbers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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