Categorygithub.com/Cyb3r-Jak3/common/v4
modulepackage
4.2.0
Repository: https://github.com/cyb3r-jak3/common.git
Documentation: pkg.go.dev

# README

Common

Test Go Golanglint CI DeepSource Go Report Card codecov

This repo contains common code that I use between my programs. There are currently some tests and at some point I might get around to writing more.

Tested with go versions 1.16 & 1.17.

Benchmark

Benchmarks are taken from latest-ubuntu and go version 1.16.

BenchmarkJSONResponse-2      	 1392727	       859.1 ns/op	    1024 B/op	      10 allocs/op
BenchmarkWOAllowedMethod-2   	 1257962	       890.7 ns/op	    1016 B/op	      10 allocs/op
BenchmarkAllowedMethod-2     	 1000000	      1010 ns/op	    1064 B/op	      12 allocs/op
BenchmarkContentResponse-2   	 1403922	       856.2 ns/op	    1013 B/op	      10 allocs/op
BenchmarkStringResponse-2    	 1373049	       866.9 ns/op	    1016 B/op	      10 allocs/op
BenchmarkJSONMarshall-2      	 1000000	      1103 ns/op	    1024 B/op	      10 allocs/op
BenchmarkGenerate-2          	  687927	      1759 ns/op
BenchmarkJSONParse-2         	  736328	      1734 ns/op	      80 B/op	       2 allocs/op
BenchmarkYAMLParse-2         	  731004	      1747 ns/op	      80 B/op	       2 allocs/op
BenchmarkStringSearch2-2     	52436001	        22.40 ns/op
BenchmarkStringSearch10-2    	29598258	        39.59 ns/op
BenchmarkFloatSearch2-2      	100000000	        10.19 ns/op
BenchmarkFloatSearch10-2     	73469235	        16.32 ns/op
BenchmarkIntSearch2-2        	93743188	        12.67 ns/op
BenchmarkIntSearch10-2       	64075212	        18.75 ns/op
BenchmarkGetEnv-2            	30846982	        38.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetEnvMissing-2     	31355505	        37.83 ns/op
BenchmarkSHA256-2            	   72594	     16070 ns/op
BenchmarkSHA384-2            	   78955	     15485 ns/op
BenchmarkSHA512-2            	   77162	     15605 ns/op
BenchmarkToHex-2             	 7395942	       166.2 ns/op
BenchmarkSkipRoot-2          	  812551	      1494 ns/op
BenchmarkEnvironMap-2        	   45308	     26414 ns/op

# Packages

No description provided by the author

# Functions

AllowedMethod is a decorator to get methods.
ContentResponse writes a http response with a given content type.
DoJSONRequest sends a client JSON request.
DownloadFile downloads a file and writes it to the file path.
EnvironMap returns a string map of environment variables.
FloatSearch checks an array of float64 to see if the target float is in it.
GenerateRandInt securely generate a random int64.
GetEnv checks if the key exists in the environment variables.
GetEnvSecret will get either a OS environment variable.
HashFile generates a string hash of the given file path.
IntSearch checks an array of ints to see if the target int is in it.
JSONMarshalResponse writes a http response as JSON.
JSONResponse writes a http response as JSON.
ParseYamlOrJSON will detect if a file is either a JSON or YAML file and marshal it to the provided interface.
SkipRoot skips the root struct of a JSON message but will return nil if an error happens.
SkipRootwithError skips the root struct of a JSON message but will return an error.
StringResponse writes a http response as a string.
StringSearch checks an array of strings to see if the target string is in it.

# Constants

JSONApplicationType is MIME type for json data.