Skip to content

Commit 6e3c484

Browse files
authored
Feat/#7/localmessaging (#77)
* [#7] Improved messaging and refactored local messaging * [#7] Updated gitignore * [#7] messaging imporvements * [#75] Fixed the bug * [#76] Added Go report card * [#76] Fixed released date * [#76] Latest Version * Fixed test case
1 parent 3e96b90 commit 6e3c484

22 files changed

+335
-332
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
.DS_Store
77

8-
main.go
8+
main.go
9+
log-config.json

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
[![report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/oss.nandlabs.io/golly)
12
[![testing](https://img.shields.io/github/actions/workflow/status/nandlabs/golly/go_ci.yml?branch=main&event=push&color=228B22)](https://github.com/nandlabs/golly/actions?query=event%3Apush+branch%3Amain+)
2-
[![release](https://img.shields.io/github/v/release/nandlabs/golly?label=Latest&color=228B22)](https://github.com/nandlabs/golly/releases/latest)
3-
[![releaseDate](https://img.shields.io/github/release-date/nandlabs/golly?label=Released&color=228B22)](https://github.com/nandlabs/golly/releases/latest)
4-
![Go Version](https://img.shields.io/github/go-mod/go-version/nandlabs/golly?label=Go&color=00ADD8)
3+
[![release](https://img.shields.io/github/v/release/nandlabs/golly?label=latest&color=228B22)](https://github.com/nandlabs/golly/releases/latest)
4+
[![releaseDate](https://img.shields.io/github/release-date/nandlabs/golly?label=released&color=00ADD8)](https://github.com/nandlabs/golly/releases/latest)
55
[![godoc](https://godoc.org/oss.nandlabs.io/golly?status.svg)](https://pkg.go.dev/oss.nandlabs.io/golly)
66

77
# golly

config/attributes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package config
22

3-
// Interface Attirbutes is the interface that represents the attributes of a message
3+
// Interface Attributes is the interface that represents the attributes of a message
44
type Attributes interface {
55
// Set adds a new attribute to the message
66
Set(k string, v any)

config/environment.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"strconv"
77
)
88

9-
//GetEnvAsString function will fetch the val from environment variable.
10-
//If the value is absent then it will return defaultVal supplied.
9+
// GetEnvAsString function will fetch the val from environment variable.
10+
// If the value is absent then it will return defaultVal supplied.
1111
func GetEnvAsString(key, defaultVal string) string {
1212
if val, ok := os.LookupEnv(key); ok {
1313
return val
@@ -16,35 +16,35 @@ func GetEnvAsString(key, defaultVal string) string {
1616

1717
}
1818

19-
//GetEnvAsInt function will fetch the val from environment variable and convert that to an integer.
20-
//If the value is absent then it will return defaultVal supplied.
19+
// GetEnvAsInt function will fetch the val from environment variable and convert that to an integer.
20+
// If the value is absent then it will return defaultVal supplied.
2121
func GetEnvAsInt(key string, defaultVal int) (int, error) {
2222
if val, ok := os.LookupEnv(key); ok {
2323
return strconv.Atoi(val)
2424
}
2525
return defaultVal, nil
2626
}
2727

28-
//GetEnvAsInt64 function will fetch the val from environment variable and convert that to an integer of 64 bit.
29-
//If the value is absent then it will return defaultVal supplied.
28+
// GetEnvAsInt64 function will fetch the val from environment variable and convert that to an integer of 64 bit.
29+
// If the value is absent then it will return defaultVal supplied.
3030
func GetEnvAsInt64(key string, defaultVal int64) (int64, error) {
3131
if val, ok := os.LookupEnv(key); ok {
3232
return strconv.ParseInt(val, 10, 64)
3333
}
3434
return defaultVal, nil
3535
}
3636

37-
//GetEnvAsDecimal function will fetch the val from environment variable and convert that to an float64.
38-
//If the value is absent then it will return defaultVal supplied.
37+
// GetEnvAsDecimal function will fetch the val from environment variable and convert that to an float64.
38+
// If the value is absent then it will return defaultVal supplied.
3939
func GetEnvAsDecimal(key string, defaultVal float64) (float64, error) {
4040
if val, ok := os.LookupEnv(key); ok {
4141
return strconv.ParseFloat(val, 64)
4242
}
4343
return defaultVal, nil
4444
}
4545

46-
//GetEnvAsBool function will fetch the val from environment variable and convert that to an GetEnvAsBool.
47-
//If the value is absent then it will return defaultVal supplied.
46+
// GetEnvAsBool function will fetch the val from environment variable and convert that to an GetEnvAsBool.
47+
// If the value is absent then it will return defaultVal supplied.
4848
// Valid boolean vals are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
4949
func GetEnvAsBool(key string, defaultVal bool) (bool, error) {
5050
if val, ok := os.LookupEnv(key); ok {

ioutils/io_utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@ import "io"
55
var CloserFunc = func(closer io.Closer) {
66
_ = closer.Close()
77
}
8+
9+
func IsChanClosed[T any](ch chan T) (closed bool) {
10+
select {
11+
case <-ch:
12+
closed = true
13+
default:
14+
closed = false
15+
}
16+
return
17+
}
18+
19+
func CloseChannel[T any](ch chan T) {
20+
if !IsChanClosed(ch) {
21+
close(ch)
22+
}
23+
}

l3/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// Packge l3 provides multi level logging for Go applications.
1+
// Package l3 provides multi level logging for Go applications.
22
package l3

l3/l3_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package l3
22

3-
//LogConfig - Configuration & Settings for the logger.
3+
// LogConfig - Configuration & Settings for the logger.
44
type LogConfig struct {
55

66
//Format of the log. valid values are text,json
@@ -38,15 +38,15 @@ type PackageConfig struct {
3838
Level string `json:"level" yaml:"level"`
3939
}
4040

41-
//WriterConfig struct
41+
// WriterConfig struct
4242
type WriterConfig struct {
4343
//File reference. Non mandatory but one of file or console logger is required.
4444
File *FileConfig `json:"file,omitempty" yaml:"file,omitempty"`
4545
//Console reference
4646
Console *ConsoleConfig `json:"console,omitempty" yaml:"console,omitempty"`
4747
}
4848

49-
//FileConfig - Configuration of file based logging
49+
// FileConfig - Configuration of file based logging
5050
type FileConfig struct {
5151
//FilePath for the file based log writer
5252
DefaultPath string `json:"defaultPath" yaml:"defaultPath"`

l3/logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const (
1515
Trace
1616
)
1717

18-
//Level specifies the log level
18+
// Level specifies the log level
1919
type Level int
2020

21-
//Levels of the logging by severity
21+
// Levels of the logging by severity
2222
var Levels = [...]string{
2323
"OFF",
2424
"ERROR",
@@ -38,7 +38,7 @@ var LevelsBytes = [...][]byte{
3838
[]byte("TRACE"),
3939
}
4040

41-
//LevelsMap of the logging by Level string Level type
41+
// LevelsMap of the logging by Level string Level type
4242
var LevelsMap = map[string]Level{
4343
"OFF": Off,
4444
"ERROR": Err,

managers/item_manager_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ func TestItemManager_Items(t *testing.T) {
2828
manager.Register("item3", 3)
2929

3030
items := manager.Items()
31-
expectedItems := []int{1, 2, 3}
3231

33-
assert.Equal(t, expectedItems, items)
32+
assert.ListHas(t, 1, items)
33+
assert.ListHas(t, 2, items)
34+
assert.ListHas(t, 3, items)
3435
}
3536

3637
func TestItemManager_Items_Empty(t *testing.T) {

messaging/base_message.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ package messaging
33
import (
44
"bytes"
55
"io"
6-
"oss.nandlabs.io/golly/codec"
76
"reflect"
7+
8+
"oss.nandlabs.io/golly/codec"
89
)
910

1011
type BaseMessage struct {
12+
id string
1113
headers map[string]interface{}
1214
headerTypes map[string]reflect.Kind
1315
body *bytes.Buffer
1416
}
1517

18+
func (bm *BaseMessage) Id() string {
19+
return bm.id
20+
}
21+
1622
func (bm *BaseMessage) SetBodyStr(input string) (n int, err error) {
1723
n, err = bm.body.WriteString(input)
1824
return

0 commit comments

Comments
 (0)