├── .gitignore ├── math ├── types.go ├── float64.go └── float64_test.go ├── go.mod ├── nocopy ├── nocopy.go └── types.go ├── .github └── workflows │ ├── lint.yml │ └── test.yml ├── bytes ├── const.go ├── bytes.go └── bytes_test.go ├── ulid ├── ulid.go └── ulid_test.go ├── sync └── waitgroup.go ├── README.md ├── strconv ├── strconv.go └── strconv_test.go ├── time ├── ticker.go └── timer.go ├── go.sum ├── uuid ├── uuid.go └── uuid_test.go ├── encoding └── base64 │ ├── base64.go │ └── base64_test.go ├── .golangci.yml ├── strings ├── strings.go └── strings_test.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | -------------------------------------------------------------------------------- /math/types.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | // Float64Calculator is a calculator for float64 values. 4 | type Float64Calculator struct{} 5 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/savsgio/gotils 2 | 3 | go 1.21 4 | 5 | require ( 6 | github.com/google/uuid v1.6.0 7 | github.com/oklog/ulid/v2 v2.1.1 8 | github.com/valyala/bytebufferpool v1.0.0 9 | ) 10 | -------------------------------------------------------------------------------- /nocopy/nocopy.go: -------------------------------------------------------------------------------- 1 | package nocopy 2 | 3 | // Lock is a no-op implementation of the sync.Locker interface. 4 | func (*NoCopy) Lock() {} 5 | 6 | // Unlock is a no-op implementation of the sync.Locker interface. 7 | func (*NoCopy) Unlock() {} 8 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: [push, pull_request] 3 | jobs: 4 | lint: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v5 8 | - uses: golangci/golangci-lint-action@v8 9 | with: 10 | version: v2.5.0 11 | -------------------------------------------------------------------------------- /bytes/const.go: -------------------------------------------------------------------------------- 1 | package bytes 2 | 3 | const ( 4 | charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | charsetIdxBits = 6 // 6 bits to represent a charset index 6 | charsetIdxMask = 1< 0 { 54 | b = append(b, make([]byte, n)...) 55 | } 56 | 57 | return b[:needLen] 58 | } 59 | 60 | // Prepend prepends bytes into a given byte slice. 61 | func Prepend(dst []byte, src ...byte) []byte { 62 | dstLen := len(dst) 63 | srcLen := len(src) 64 | 65 | dst = Extend(dst, dstLen+srcLen) 66 | copy(dst[srcLen:], dst[:dstLen]) 67 | copy(dst[:srcLen], src) 68 | 69 | return dst 70 | } 71 | 72 | // PrependString prepends a string into a given byte slice. 73 | func PrependString(dst []byte, src string) []byte { 74 | return Prepend(dst, strconv.S2B(src)...) 75 | } 76 | -------------------------------------------------------------------------------- /math/float64.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | import ( 4 | "bytes" 5 | "math" 6 | "strconv" 7 | 8 | "github.com/valyala/bytebufferpool" 9 | ) 10 | 11 | // NewFloat64Calculator returns a float64 calculator 12 | // for basic operations without losing precision in decimals. 13 | func NewFloat64Calculator() *Float64Calculator { 14 | return &Float64Calculator{} 15 | } 16 | 17 | // DecimalPlaces returns the number of decimal places. 18 | func (fc *Float64Calculator) DecimalPlaces(x float64) int { 19 | buf := bytebufferpool.Get() 20 | defer bytebufferpool.Put(buf) 21 | 22 | buf.B = strconv.AppendFloat(buf.B, x, 'f', -1, 64) 23 | i := bytes.IndexByte(buf.B, '.') 24 | 25 | if i > -1 { 26 | return len(buf.B) - i - 1 27 | } 28 | 29 | return 0 30 | } 31 | 32 | // Max returns the larger of x or y. 33 | func (fc *Float64Calculator) Max(x, y int) int { 34 | if x > y { 35 | return x 36 | } 37 | 38 | return y 39 | } 40 | 41 | // Add returns a + b. 42 | func (fc *Float64Calculator) Add(a, b float64) float64 { 43 | exp := math.Pow10(fc.Max(fc.DecimalPlaces(a), fc.DecimalPlaces(b))) 44 | 45 | intA := math.Round(a * exp) 46 | intB := math.Round(b * exp) 47 | 48 | return (intA + intB) / exp 49 | } 50 | 51 | // Sub returns a - b. 52 | func (fc *Float64Calculator) Sub(a, b float64) float64 { 53 | exp := math.Pow10(fc.Max(fc.DecimalPlaces(a), fc.DecimalPlaces(b))) 54 | 55 | intA := math.Round(a * exp) 56 | intB := math.Round(b * exp) 57 | 58 | return (intA - intB) / exp 59 | } 60 | 61 | // Mul returns a * b. 62 | func (fc *Float64Calculator) Mul(a, b float64) float64 { 63 | placesA := fc.DecimalPlaces(a) 64 | placesB := fc.DecimalPlaces(b) 65 | 66 | expA := math.Pow10(placesA) 67 | expB := math.Pow10(placesB) 68 | 69 | intA := math.Round(a * expA) 70 | intB := math.Round(b * expB) 71 | 72 | exp := math.Pow10(placesA + placesB) 73 | 74 | return (intA * intB) / exp 75 | } 76 | 77 | // Div returns a / b. 78 | func (fc *Float64Calculator) Div(a, b float64) float64 { 79 | placesA := fc.DecimalPlaces(a) 80 | placesB := fc.DecimalPlaces(b) 81 | 82 | expA := math.Pow10(placesA) 83 | expB := math.Pow10(placesB) 84 | 85 | intA := math.Round(a * expA) 86 | intB := math.Round(b * expB) 87 | 88 | exp := math.Pow10(placesA - placesB) 89 | 90 | return (intA / intB) / exp 91 | } 92 | 93 | // Mod returns a % b. 94 | func (fc *Float64Calculator) Mod(a, b float64) float64 { 95 | quo := math.Round(fc.Div(a, b)) 96 | 97 | return fc.Sub(a, fc.Mul(b, quo)) 98 | } 99 | -------------------------------------------------------------------------------- /encoding/base64/base64_test.go: -------------------------------------------------------------------------------- 1 | // See https://go-review.googlesource.com/c/go/+/37639/1/src/encoding/base64/base64_test.go#18 2 | 3 | package base64 4 | 5 | import ( 6 | "encoding/base64" 7 | "testing" 8 | ) 9 | 10 | type testpair struct { 11 | decoded, encoded string 12 | } 13 | 14 | var pairs = []testpair{ 15 | // RFC 3548 examples 16 | {"\x14\xfb\x9c\x03\xd9\x7e", "FPucA9l+"}, 17 | {"\x14\xfb\x9c\x03\xd9", "FPucA9k="}, 18 | {"\x14\xfb\x9c\x03", "FPucAw=="}, 19 | 20 | // RFC 4648 examples 21 | {"", ""}, 22 | {"f", "Zg=="}, 23 | {"fo", "Zm8="}, 24 | {"foo", "Zm9v"}, 25 | {"foob", "Zm9vYg=="}, 26 | {"fooba", "Zm9vYmE="}, 27 | {"foobar", "Zm9vYmFy"}, 28 | 29 | // Wikipedia examples 30 | {"sure.", "c3VyZS4="}, 31 | {"sure", "c3VyZQ=="}, 32 | {"sur", "c3Vy"}, 33 | {"su", "c3U="}, 34 | {"leasure.", "bGVhc3VyZS4="}, 35 | {"easure.", "ZWFzdXJlLg=="}, 36 | {"asure.", "YXN1cmUu"}, 37 | {"sure.", "c3VyZS4="}, 38 | } 39 | 40 | func testEqual(t *testing.T, msg string, args ...any) { // nolint:thelper 41 | if args[len(args)-2] != args[len(args)-1] { 42 | t.Errorf(msg, args...) 43 | } 44 | } 45 | 46 | func TestAppendEncode(t *testing.T) { 47 | var dbuf []byte 48 | 49 | for _, p := range pairs { 50 | b := AppendEncode(base64.StdEncoding, dbuf, []byte(p.decoded)) 51 | count := len(b) - len(dbuf) 52 | 53 | testEqual(t, "AppendEncode(%q) = length %v, want %v", p.decoded, count, len(p.encoded)) 54 | testEqual(t, "AppendEncode(%q) = %q, want %q", p.decoded, string(b[len(dbuf):]), p.encoded) 55 | 56 | dbuf = b 57 | } 58 | } 59 | 60 | func TestAppendDecode(t *testing.T) { 61 | var dbuf []byte 62 | 63 | for _, p := range pairs { 64 | b, err := AppendDecode(base64.StdEncoding, dbuf, []byte(p.encoded)) 65 | count := len(b) - len(dbuf) 66 | 67 | testEqual(t, "AppendDecode(%q) = error %v, want %v", p.encoded, err, error(nil)) 68 | testEqual(t, "AppendDecode(%q) = length %v, want %v", p.encoded, count, len(p.decoded)) 69 | testEqual(t, "AppendDecode(%q) = %q, want %q", p.encoded, string(b[len(dbuf):]), p.decoded) 70 | 71 | dbuf = b 72 | } 73 | } 74 | 75 | func BenchmarkAppendEncode(b *testing.B) { 76 | var dbuf []byte 77 | 78 | data := make([]byte, 8192) 79 | b.SetBytes(int64(len(data))) 80 | 81 | for i := 0; i < b.N; i++ { 82 | dbuf = AppendEncode(base64.StdEncoding, dbuf[:0], data) 83 | } 84 | } 85 | 86 | func BenchmarkAppendDecode(b *testing.B) { 87 | var dbuf []byte 88 | 89 | data := AppendEncode(base64.StdEncoding, nil, make([]byte, 8192)) 90 | b.SetBytes(int64(len(data))) 91 | 92 | for i := 0; i < b.N; i++ { 93 | dbuf, _ = AppendDecode(base64.StdEncoding, dbuf[:0], data) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /math/float64_test.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | ) 7 | 8 | func TestFloat64Calculator_Add(t *testing.T) { 9 | fc := NewFloat64Calculator() 10 | 11 | x := 1.0 12 | y := 0.1 13 | 14 | for i := 0; i < 10; i++ { 15 | x = fc.Add(x, y) 16 | } 17 | 18 | want := 2.0 19 | 20 | if want != x { 21 | t.Errorf("Add() == %v, want %v", want, x) 22 | } 23 | } 24 | 25 | func TestFloat64Calculator_Sub(t *testing.T) { 26 | fc := NewFloat64Calculator() 27 | 28 | x := 1.0 29 | y := 0.1 30 | 31 | for i := 0; i < 10; i++ { 32 | x = fc.Sub(x, y) 33 | } 34 | 35 | want := 0.0 36 | 37 | if want != x { 38 | t.Errorf("Sub() == %v, want %v", want, x) 39 | } 40 | } 41 | 42 | func TestFloat64Calculator_Mul(t *testing.T) { 43 | fc := NewFloat64Calculator() 44 | 45 | x := 1.0 46 | y := 0.1 47 | 48 | for i := 0; i < 10; i++ { 49 | x = fc.Mul(x, y) 50 | } 51 | 52 | want := math.Pow10(-10) 53 | 54 | if want != x { 55 | t.Errorf("Mul() == %v, want %v", x, want) 56 | } 57 | } 58 | 59 | func TestFloat64Calculator_Div(t *testing.T) { 60 | fc := NewFloat64Calculator() 61 | 62 | x := 1.0 63 | y := 0.1 64 | 65 | for i := 0; i < 10; i++ { 66 | x = fc.Div(x, y) 67 | } 68 | 69 | want := math.Pow10(10) 70 | 71 | if want != x { 72 | t.Errorf("Div() == %v, want %v", want, x) 73 | } 74 | } 75 | 76 | func BenchmarkFloat64Calculator_Add(b *testing.B) { 77 | fc := NewFloat64Calculator() 78 | 79 | x := 1.2345 80 | y := 6.789123 81 | 82 | b.ResetTimer() 83 | 84 | for i := 0; i < b.N; i++ { 85 | fc.Add(x, y) 86 | } 87 | } 88 | 89 | func BenchmarkFloat64Calculator_Sub(b *testing.B) { 90 | fc := NewFloat64Calculator() 91 | 92 | x := 1.2345 93 | y := 6.789123 94 | 95 | b.ResetTimer() 96 | 97 | for i := 0; i < b.N; i++ { 98 | fc.Sub(x, y) 99 | } 100 | } 101 | 102 | func BenchmarkFloat64Calculator_Mul(b *testing.B) { 103 | fc := NewFloat64Calculator() 104 | 105 | x := 1.2345 106 | y := 6.789123 107 | 108 | b.ResetTimer() 109 | 110 | for i := 0; i < b.N; i++ { 111 | fc.Mul(x, y) 112 | } 113 | } 114 | 115 | func BenchmarkFloat64Calculator_Div(b *testing.B) { 116 | fc := NewFloat64Calculator() 117 | 118 | x := 1.2345 119 | y := 6.789123 120 | 121 | b.ResetTimer() 122 | 123 | for i := 0; i < b.N; i++ { 124 | fc.Div(x, y) 125 | } 126 | } 127 | 128 | func BenchmarkFloat64Calculator_Mod(b *testing.B) { 129 | fc := NewFloat64Calculator() 130 | 131 | x := 1.2345 132 | y := 6.789123 133 | 134 | b.ResetTimer() 135 | 136 | for i := 0; i < b.N; i++ { 137 | fc.Mod(x, y) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /strings/strings_test.go: -------------------------------------------------------------------------------- 1 | package strings 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func Test_Copy(t *testing.T) { 9 | str := "cache" 10 | result := Copy(str) 11 | 12 | if reflect.ValueOf(&str).Pointer() == reflect.ValueOf(&result).Pointer() { 13 | t.Errorf("Copy() returns the same pointer (source == %p | result == %p)", &str, &result) 14 | } 15 | } 16 | 17 | func Test_UniqueAppend(t *testing.T) { 18 | slice := []string{"kratgo", "fast", "http", "cache"} 19 | slice2 := CopySlice(slice) 20 | 21 | result := UniqueAppend(slice, slice[0]) 22 | if len(result) != len(slice) { 23 | t.Errorf("UniqueAppend() == %v, want %v", result, slice) 24 | } 25 | 26 | slice2 = append(slice2, "unique") 27 | 28 | result = UniqueAppend(slice, slice2...) 29 | if len(result) == len(slice) { 30 | t.Errorf("UniqueAppend() == %v, want %v", result, slice2) 31 | } 32 | } 33 | 34 | // ------------------------------------------------------------ 35 | // DEPRECATED 36 | // ------------------------------------------------------------ 37 | 38 | func Test_CopySlice(t *testing.T) { 39 | slice := []string{"kratgo", "fast", "http", "cache"} 40 | 41 | result := CopySlice(slice) 42 | 43 | if !reflect.DeepEqual(result, slice) { 44 | t.Errorf("CopySlice() == %v, want %v", result, slice) 45 | } 46 | } 47 | 48 | func Test_IndexOf(t *testing.T) { 49 | slice := []string{"kratgo", "fast", "http", "cache"} 50 | 51 | s := "fast" 52 | if i := IndexOf(slice, s); i < 0 { 53 | t.Errorf("stringSliceIndexOf() = %v, want %v", i, 2) 54 | } 55 | 56 | s = "slow" 57 | if i := IndexOf(slice, s); i > -1 { 58 | t.Errorf("stringSliceIndexOf() = %v, want %v", i, -1) 59 | } 60 | } 61 | 62 | func Test_Include(t *testing.T) { 63 | slice := []string{"kratgo", "fast", "http", "cache"} 64 | 65 | s := "fast" 66 | if ok := Include(slice, s); !ok { 67 | t.Errorf("stringSliceInclude() = %v, want %v", ok, true) 68 | } 69 | 70 | s = "slow" 71 | if ok := Include(slice, s); ok { 72 | t.Errorf("stringSliceInclude() = %v, want %v", ok, false) 73 | } 74 | } 75 | 76 | func Test_EqualSlices(t *testing.T) { 77 | slice1 := []string{"kratgo", "fast", "http", "cache"} 78 | slice2 := []string{"kratgo", "fast", "http", "cache"} 79 | 80 | if !EqualSlices(slice1, slice2) { 81 | t.Errorf("EqualSlices() == %v, want %v", false, true) 82 | } 83 | 84 | slice1 = []string{"kratgo", "fast", "http", "cache"} 85 | slice2 = []string{"kratgo", "fast", "http"} 86 | 87 | if EqualSlices(slice1, slice2) { 88 | t.Errorf("EqualSlices() == %v, want %v", true, false) 89 | } 90 | 91 | slice1 = []string{"kratgo", "fast", "http", "cache"} 92 | slice2 = []string{"kratgo", "fast", "rpc", "cache"} 93 | 94 | if EqualSlices(slice1, slice2) { 95 | t.Errorf("EqualSlices() == %v, want %v", true, false) 96 | } 97 | } 98 | 99 | func Test_ReverseSlice(t *testing.T) { 100 | slice := []string{"kratgo", "fast", "http", "cache"} 101 | reversedSlice := []string{"cache", "http", "fast", "kratgo"} 102 | 103 | result := ReverseSlice(slice) 104 | 105 | if !EqualSlices(result, reversedSlice) { 106 | t.Errorf("ReverseSlice() == %v, want %v", result, reversedSlice) 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /bytes/bytes_test.go: -------------------------------------------------------------------------------- 1 | package bytes 2 | 3 | import ( 4 | "reflect" 5 | "slices" 6 | "sync" 7 | "testing" 8 | ) 9 | 10 | func testRand(t *testing.T) { 11 | t.Helper() 12 | 13 | values := make([]string, 0) 14 | 15 | for i := 0; i < 10000; i++ { 16 | n := 32 17 | dst := make([]byte, n) 18 | 19 | Rand(dst) 20 | 21 | if slices.Contains(values, string(dst)) { 22 | t.Error("Rand() returns the same value") 23 | 24 | return 25 | } 26 | 27 | values = append(values, string(dst)) 28 | 29 | for i := range dst { 30 | if string(rune(i)) == "" { 31 | t.Errorf("RandBytes() invalid char '%v'", dst[i]) 32 | } 33 | } 34 | 35 | if len(dst) != n { 36 | t.Errorf("RandBytes() length '%d', want '%d'", len(dst), n) 37 | } 38 | } 39 | } 40 | 41 | func Test_Rand(t *testing.T) { 42 | testRand(t) 43 | } 44 | 45 | func Test_RandConcurrent(t *testing.T) { 46 | n := 32 47 | wg := sync.WaitGroup{} 48 | 49 | for i := 0; i < n; i++ { 50 | wg.Add(1) 51 | 52 | go func() { 53 | defer wg.Done() 54 | 55 | testRand(t) 56 | }() 57 | } 58 | 59 | wg.Wait() 60 | } 61 | 62 | func Test_Copy(t *testing.T) { 63 | str := []byte("cache") 64 | result := Copy(str) 65 | 66 | if reflect.ValueOf(&str).Pointer() == reflect.ValueOf(&result).Pointer() { 67 | t.Errorf("Copy() returns the same pointer (source == %p | result == %p)", &str, &result) 68 | } 69 | } 70 | 71 | func Test_Equal(t *testing.T) { 72 | foo := []byte("foo") 73 | bar := []byte("bar") 74 | 75 | if isEqual := Equal(foo, bar); isEqual { 76 | t.Errorf("Equal(%s, %s) == %v, want %v", foo, bar, isEqual, false) 77 | } 78 | 79 | if isEqual := Equal(foo, foo); !isEqual { 80 | t.Errorf("Equal(%s, %s) == %v, want %v", foo, foo, isEqual, true) 81 | } 82 | } 83 | 84 | func Test_Extend(t *testing.T) { 85 | type args struct { 86 | b []byte 87 | needLen int 88 | } 89 | 90 | type want struct { 91 | sliceLen int 92 | } 93 | 94 | tests := []struct { 95 | name string 96 | args args 97 | want want 98 | }{ 99 | { 100 | name: "Initial 0", 101 | args: args{ 102 | b: make([]byte, 0), 103 | needLen: 10, 104 | }, 105 | want: want{ 106 | sliceLen: 10, 107 | }, 108 | }, 109 | { 110 | name: "Initial 10", 111 | args: args{ 112 | b: make([]byte, 10), 113 | needLen: 5, 114 | }, 115 | want: want{ 116 | sliceLen: 5, 117 | }, 118 | }, 119 | { 120 | name: "Initial 69", 121 | args: args{ 122 | b: make([]byte, 45), 123 | needLen: 69, 124 | }, 125 | want: want{ 126 | sliceLen: 69, 127 | }, 128 | }, 129 | } 130 | 131 | for _, tt := range tests { 132 | b := tt.args.b 133 | needLen := tt.args.needLen 134 | sliceLen := tt.want.sliceLen 135 | 136 | t.Run(tt.name, func(t *testing.T) { 137 | got := Extend(b, needLen) 138 | 139 | gotLen := len(got) 140 | if gotLen != sliceLen { 141 | t.Errorf("ExtendByteSlice() length = %v, want = %v", gotLen, sliceLen) 142 | } 143 | }) 144 | } 145 | } 146 | 147 | func Test_Prepend(t *testing.T) { 148 | foo := []byte("foo") 149 | bar := []byte("bar") 150 | 151 | expected := []byte("foobar") 152 | result := Prepend(bar, foo...) 153 | 154 | if isEqual := Equal(result, expected); !isEqual { 155 | t.Errorf("Prepend() == %s, want %s", result, expected) 156 | } 157 | } 158 | 159 | func Test_PrependString(t *testing.T) { 160 | foo := "foo" 161 | bar := []byte("bar") 162 | 163 | expected := []byte("foobar") 164 | result := PrependString(bar, foo) 165 | 166 | if isEqual := Equal(result, expected); !isEqual { 167 | t.Errorf("Prepend() == %s, want %s", result, expected) 168 | } 169 | } 170 | 171 | func Benchmark_Rand(b *testing.B) { 172 | n := 32 173 | dst := make([]byte, n) 174 | 175 | b.RunParallel(func(pb *testing.PB) { 176 | for pb.Next() { 177 | Rand(dst) 178 | } 179 | }) 180 | } 181 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020-present Sergio Andres Virviescas Santana 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------