Skip to content

Commit

Permalink
update almost all sub-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonWaldherr committed Apr 7, 2023
1 parent 2bc17ab commit 671d7fb
Show file tree
Hide file tree
Showing 24 changed files with 1,041 additions and 31 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ go test ./...

. | service | info
---|---------|------
![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square) | | go test ./...
![OSX Build Status](https://simonwaldherr.de/icon/osx.png) | ![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square) | | go test ./...
[![Audit](https://github.com/SimonWaldherr/golibs/actions/workflows/audit.yml/badge.svg?branch=master&event=push)](https://github.com/SimonWaldherr/golibs/actions/workflows/audit.yml) | github.com | test via GitHub Workflow
[![Travis CI](https://app.travis-ci.com/SimonWaldherr/golibs.svg?branch=master)](https://app.travis-ci.com/SimonWaldherr/golibs) | travis-ci.com | test at travis-ci
[![Build Status](https://semaphoreci.com/api/v1/simonwaldherr/golibs/branches/master/shields_badge.svg)](https://semaphoreci.com/simonwaldherr/golibs) | semaphoreci.com | test at semaphore-ci
Expand Down Expand Up @@ -135,7 +135,7 @@ var x int = as.Int("32")
var x time.Time = as.Time("31.12.2014")
```

### bitmask - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/bitmask) [![Coverage Status](https://img.shields.io/badge/coverage-92%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### bitmask - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/bitmask) [![Coverage Status](https://img.shields.io/badge/coverage-0%25-red.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)

```go
import "simonwaldherr.de/go/golibs/bitmask"
Expand All @@ -148,7 +148,7 @@ i := bitmask.New(0b11111111)
i.Set(0, false)
```

### cache - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/cache) [![Coverage Status](https://img.shields.io/badge/coverage-97%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### cache - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/cache) [![Coverage Status](https://img.shields.io/badge/coverage-93%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)

```go
import "simonwaldherr.de/go/golibs/cache"
Expand Down Expand Up @@ -178,7 +178,7 @@ str, _ := cachedfile.Read("filename.txt")
and there will be no file access to disk.
If you kill the App, wait 15 min or call ```cachedfile.Stop()``` the cached content will be exported to disk.

### channel - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/channel) [![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### channel - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/channel) [![Coverage Status](https://img.shields.io/badge/coverage-73%25-yellowgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)

```go
import "simonwaldherr.de/go/golibs/channel"
Expand Down Expand Up @@ -242,7 +242,7 @@ err := file.Each("..", true, func(filename, extension, filepath string, dir bool

If you need the absolute path to a file, but only have a relative path, you can use ```file.GetAbsolutePath("~/path/to/file.txt")```.

### foreach - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/foreach) [![Coverage Status](https://img.shields.io/badge/coverage-90%25-green.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### foreach - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/foreach) [![Coverage Status](https://img.shields.io/badge/coverage-42%25-red.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)

```go
import "simonwaldherr.de/go/golibs/foreach"
Expand Down Expand Up @@ -314,7 +314,7 @@ func main() {
...
```
### graphics - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/graphics) [![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### graphics - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/graphics) [![Coverage Status](https://img.shields.io/badge/coverage-94%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
```go
import "simonwaldherr.de/go/golibs/graphics"
Expand Down Expand Up @@ -346,7 +346,7 @@ fd.Close()
```
### http - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/http) [![Coverage Status](https://img.shields.io/badge/coverage-83%25-green.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### http - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/http) [![Coverage Status](https://img.shields.io/badge/coverage-8%25-red.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
```go
import "simonwaldherr.de/go/golibs/http"
Expand Down Expand Up @@ -418,7 +418,7 @@ err := ssl.Generate(options)
```
### stack - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/stack) [![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### stack - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/stack) [![Coverage Status](https://img.shields.io/badge/coverage-97%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
```go
import "simonwaldherr.de/go/golibs/stack"
Expand Down Expand Up @@ -463,7 +463,7 @@ fmt.Printf("Harmonic: %v\n", xmath.Harmonic(f))
fmt.Printf("Geometric: %v\n", xmath.Geometric(f))
```
### xtime - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/xtime) [![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
### xtime - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/xtime) [![Coverage Status](https://img.shields.io/badge/coverage-43%25-red.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs) [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)
```go
import "simonwaldherr.de/go/golibs/xtime"
Expand Down
8 changes: 8 additions & 0 deletions bitmask/bitmask.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// bitmasks are a way to store multiple boolean values in a single integer
package bitmask

import "fmt"
Expand All @@ -6,6 +7,7 @@ type Bitmask struct {
value int
}

// New creates a new Bitmask
func New(init int) *Bitmask {
return &Bitmask{value: init}
}
Expand All @@ -21,29 +23,35 @@ func (b *Bitmask) clearBit(pos int) int {
return b.value
}

// Set sets the bit at position pos to val
func (b *Bitmask) Set(pos int, val bool) int {
if val == true {
return b.setBit(pos)
}
return b.clearBit(pos)
}

// hasBit checks if the bit at position pos is set
func (b *Bitmask) hasBit(pos int) bool {
return ((b.value & (1 << pos)) > 0)
}

// Get returns the value of the bit at position pos
func (b *Bitmask) Get(pos int) bool {
return b.hasBit(pos)
}

// Int returns the integer value of the bitmask
func (b *Bitmask) Int() int {
return b.value
}

// String returns the string representation of the bitmask
func (b *Bitmask) String() string {
return fmt.Sprintf("%b", b.value)
}

// Byte returns the byte representation of the bitmask
func (b *Bitmask) Byte() []byte {
return []byte{byte(b.value)}
}
34 changes: 34 additions & 0 deletions channel/channel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// channel is a simple communication hub for go routines
package channel

type Communication struct {
Expand All @@ -7,6 +8,7 @@ type Communication struct {
messages chan interface{}
}

// Init creates a new Communication
func Init() *Communication {
var hub = &Communication{
receiver: make(map[chan interface{}]bool),
Expand Down Expand Up @@ -38,21 +40,53 @@ func Init() *Communication {
return hub
}

// AddReceiver adds a new receiver to the hub
func (hub *Communication) AddReceiver() chan interface{} {
messageChannel := make(chan interface{})
hub.addReceiver <- messageChannel
return messageChannel
}

// CloseReceiver closes a receiver
func (hub *Communication) CloseReceiver(ch chan interface{}) int {
hub.rmReceiver <- ch
return hub.CountReceiver()
}

// CountReceiver returns the number of receivers
func (hub *Communication) CountReceiver() int {
return len(hub.receiver)
}

// AddTransmitter adds a new transmitter to the hub
func (hub *Communication) AddTransmitter() chan<- interface{} {
return hub.messages
}

// Close closes the hub
func (hub *Communication) Close() {
close(hub.messages)
}

// CloseTransmitter closes a transmitter
func (hub *Communication) CloseTransmitter(ch chan<- interface{}) {
close(ch)
}

// CloseAll closes all receivers and transmitters
func (hub *Communication) CloseAll() {
for rec := range hub.receiver {
hub.CloseReceiver(rec)
}
hub.Close()
}

// Send sends a message to all receivers
func (hub *Communication) Send(message interface{}) {
hub.messages <- message
}

// SendTo sends a message to a specific receiver
func (hub *Communication) SendTo(message interface{}, receiver chan interface{}) {
receiver <- message
}
51 changes: 51 additions & 0 deletions coverage.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
COVERAGE TEST
ansi _/Users/simonwaldherr/git/golibs/ansi coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/ansi 0.074s coverage: 100.0% of statements
arg _/Users/simonwaldherr/git/golibs/arg coverage: 72.0% of statements
ok _/Users/simonwaldherr/git/golibs/arg 0.083s coverage: 72.0% of statements
as _/Users/simonwaldherr/git/golibs/as coverage: 98.0% of statements
ok _/Users/simonwaldherr/git/golibs/as 0.103s coverage: 98.0% of statements
bitmask _/Users/simonwaldherr/git/golibs/bitmask coverage: 0.0% of statements
ok _/Users/simonwaldherr/git/golibs/bitmask 0.095s coverage: 0.0% of statements
cache _/Users/simonwaldherr/git/golibs/cache coverage: 93.1% of statements
ok _/Users/simonwaldherr/git/golibs/cache 2.190s coverage: 93.1% of statements
cachedfile _/Users/simonwaldherr/git/golibs/cachedfile coverage: 96.0% of statements
ok _/Users/simonwaldherr/git/golibs/cachedfile 0.107s coverage: 96.0% of statements
channel _/Users/simonwaldherr/git/golibs/channel coverage: 73.1% of statements
ok _/Users/simonwaldherr/git/golibs/channel 0.106s coverage: 73.1% of statements
csv _/Users/simonwaldherr/git/golibs/csv coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/csv 0.086s coverage: 100.0% of statements
file _/Users/simonwaldherr/git/golibs/file coverage: 76.0% of statements
ok _/Users/simonwaldherr/git/golibs/file 0.141s coverage: 76.0% of statements
foreach _/Users/simonwaldherr/git/golibs/foreach coverage: 42.9% of statements
ok _/Users/simonwaldherr/git/golibs/foreach 0.113s coverage: 42.9% of statements
gopath _/Users/simonwaldherr/git/golibs/gopath coverage: 89.7% of statements
ok _/Users/simonwaldherr/git/golibs/gopath 0.091s coverage: 89.7% of statements
gps _/Users/simonwaldherr/git/golibs/gps coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/gps 0.091s coverage: 100.0% of statements
graphics _/Users/simonwaldherr/git/golibs/graphics coverage: 94.2% of statements
ok _/Users/simonwaldherr/git/golibs/graphics 3.293s coverage: 94.2% of statements
http _/Users/simonwaldherr/git/golibs/http coverage: 8.3% of statements
ok _/Users/simonwaldherr/git/golibs/http 0.098s coverage: 8.3% of statements
log _/Users/simonwaldherr/git/golibs/log coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/log 0.093s coverage: 100.0% of statements
node _/Users/simonwaldherr/git/golibs/node coverage: 92.3% of statements
ok _/Users/simonwaldherr/git/golibs/node 0.095s coverage: 92.3% of statements
re _/Users/simonwaldherr/git/golibs/re coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/re 0.617s coverage: 100.0% of statements
regex _/Users/simonwaldherr/git/golibs/regex coverage: 88.9% of statements
ok _/Users/simonwaldherr/git/golibs/regex 0.095s coverage: 88.9% of statements
rss _/Users/simonwaldherr/git/golibs/rss coverage: 92.9% of statements
ok _/Users/simonwaldherr/git/golibs/rss 1.018s coverage: 92.9% of statements
ssl _/Users/simonwaldherr/git/golibs/ssl coverage: 87.2% of statements
ok _/Users/simonwaldherr/git/golibs/ssl 0.843s coverage: 87.2% of statements
stack _/Users/simonwaldherr/git/golibs/stack coverage: 97.6% of statements
ok _/Users/simonwaldherr/git/golibs/stack 0.095s coverage: 97.6% of statements
structs _/Users/simonwaldherr/git/golibs/structs coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/structs 0.092s coverage: 100.0% of statements
xmath _/Users/simonwaldherr/git/golibs/xmath coverage: 100.0% of statements
ok _/Users/simonwaldherr/git/golibs/xmath 0.091s coverage: 100.0% of statements
xtime _/Users/simonwaldherr/git/golibs/xtime coverage: 43.8% of statements
ok _/Users/simonwaldherr/git/golibs/xtime 0.091s coverage: 43.8% of statements
yoloDB _/Users/simonwaldherr/git/golibs/yoloDB coverage: 35.6% of statements
ok _/Users/simonwaldherr/git/golibs/yoloDB 0.090s coverage: 35.6% of statements
Loading

0 comments on commit 671d7fb

Please sign in to comment.