Skip to content

Commit

Permalink
Added license prefix to all files, fixed os-specific bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
quenbyako committed Oct 30, 2020
1 parent 598e686 commit 307c5a4
Show file tree
Hide file tree
Showing 41 changed files with 399 additions and 140 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020 Xelaj Software
#
# This file is a part of go-dry package.
# See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
Expand Down
20 changes: 0 additions & 20 deletions LICENSE

This file was deleted.

25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2020` `Xelaj Software`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
go-dry
======
# go-dry

-DRY (don't repeat yourself) package for Go

-Documentation: http://pkg.go.dev/github.com/xelaj/go-dry
## bytes

## compress

## debug

## crypt

## binary

## errors

Useful stuff to do with errors

## files

## http

## io

## net

## os

## path

## rand

## reflect

## shortcuts

Useful functions to deal with go explicit result of func calling

## slice

slicetricks actually.

## maps

maptricks, you know.

## strings


## test

useful things in unit tests

## time
7 changes: 6 additions & 1 deletion bytes.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand All @@ -14,7 +19,7 @@ import (
"strings"
)

func BytesReader(data interface{}) io.Reader {
func BytesReader(data any) io.Reader {
switch s := data.(type) {
case io.Reader:
return s
Expand Down
7 changes: 6 additions & 1 deletion bytes_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand Down Expand Up @@ -27,7 +32,7 @@ func (t MyError) Error() string {

func Test_BytesReader(t *testing.T) {
expected := []byte("hello")
testBytesReaderFn := func(input interface{}) {
testBytesReaderFn := func(input any) {
result := make([]byte, 5)
returnedIoReader := BytesReader(input)
n, _ := returnedIoReader.Read(result)
Expand Down
5 changes: 5 additions & 0 deletions compression.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand Down
9 changes: 7 additions & 2 deletions debug.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand All @@ -17,7 +22,7 @@ import (
// a string and used as JSON line indent.
// If no indet argument is given, two spaces will be used
// to indent JSON lines.
func PrettyPrintAsJSON(input interface{}, indent ...string) error {
func PrettyPrintAsJSON(input any, indent ...string) error {
var indentStr string
if len(indent) == 0 {
indentStr = " "
Expand All @@ -39,7 +44,7 @@ func PrettyPrintAsJSON(input interface{}, indent ...string) error {
// Arbitrary objects can be passed as arguments to avoid "declared and not used"
// error messages when commenting code out and in.
// The result is a nil interface{} dummy value.
func Nop(dummiesIn ...interface{}) (dummyOut interface{}) {
func Nop(dummiesIn ...any) (dummyOut any) {
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package dry means DRY (don't repeat yourself) package for Go
//
// Note: This package replaces github.com/ungerik/go-quick

package dry
7 changes: 6 additions & 1 deletion encryption.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand All @@ -22,7 +27,7 @@ type aesCipherPool struct {
}

func (pool *aesCipherPool) forKey(key []byte) *sync.Pool {
return pool.poolMap.GetOrAddNew(string(key), func() interface{} {
return pool.poolMap.GetOrAddNew(string(key), func() any {
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
Expand Down
5 changes: 5 additions & 0 deletions encryption_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand Down
5 changes: 5 additions & 0 deletions endian.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand Down
5 changes: 5 additions & 0 deletions endian_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import "testing"
Expand Down
5 changes: 5 additions & 0 deletions error_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand Down
17 changes: 11 additions & 6 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

import (
Expand All @@ -7,15 +12,15 @@ import (

// PanicIfErr panics with a stack trace if any
// of the passed args is a non nil error
func PanicIfErr(args ...interface{}) {
func PanicIfErr(args ...any) {
for _, v := range args {
if err, _ := v.(error); err != nil {
panic(fmt.Sprintf("Panicking because of error: %v\n", err))
}
}
}

func PanicIf(condition bool, i ...interface{}) {
func PanicIf(condition bool, i ...any) {
if condition {
panic(fmt.Sprint(i...))
}
Expand All @@ -24,7 +29,7 @@ func PanicIf(condition bool, i ...interface{}) {
// GetError returns the last argument that is of type error,
// panics if none of the passed args is of type error.
// Note that GetError(nil) will panic because nil is not of type error but interface{}
func GetError(args ...interface{}) error {
func GetError(args ...any) error {
for i := len(args) - 1; i >= 0; i-- {
arg := args[i]
if arg != nil {
Expand All @@ -37,7 +42,7 @@ func GetError(args ...interface{}) error {
}

// AsError returns r as error, converting it when necessary
func AsError(r interface{}) error {
func AsError(r any) error {
if r == nil {
return nil
}
Expand Down Expand Up @@ -106,7 +111,7 @@ type ErrorList []error
// NewErrorList returns an ErrorList where Collect has been called for args.
// The returned list will be nil if there was no non nil error in args.
// Note that alle methods of ErrorList can be called with a nil ErrorList.
func NewErrorList(args ...interface{}) (list ErrorList) {
func NewErrorList(args ...any) (list ErrorList) {
list.Collect(args...)
return list
}
Expand Down Expand Up @@ -154,7 +159,7 @@ func (list ErrorList) Last() error {
}

// Collect adds any non nil errors in args to the list.
func (list *ErrorList) Collect(args ...interface{}) {
func (list *ErrorList) Collect(args ...any) {
for _, a := range args {
if err, _ := a.(error); err != nil {
*list = append(*list, err)
Expand Down
9 changes: 9 additions & 0 deletions extra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details

package dry

type any = interface{}
type null = struct{}
Loading

0 comments on commit 307c5a4

Please sign in to comment.