This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"os" | |
"testing" | |
"github.com/stretchr/testify/require" | |
) | |
func TestGetEnvT(t *testing.T) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"os" | |
"strconv" | |
) | |
type Env[T any] struct { | |
DefaultVal T | |
FromString func(string) (T, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AND function combines all signal from channels into a single channel with And condition | |
func AND(channels ...<-chan interface{}) <-chan interface{} { | |
switch len(channels) { | |
case 0: | |
return nil | |
case 1: | |
return channels[0] | |
} | |
andDone := make(chan interface{}) | |
collector := make(chan interface{}, len(channels)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OR function combines all signal from channels into a single channel with Or condition | |
func OR(channels ...<-chan interface{}) <-chan interface{} { | |
switch len(channels) { | |
case 0: | |
return nil | |
case 1: | |
return channels[0] | |
} | |
orDone := make(chan interface{}) | |
go func() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"sync" | |
) | |
func main() { | |
cond := sync.NewCond(&sync.Mutex{}) | |
var wg1 sync.WaitGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"strings" | |
) | |
// FileSystem custom file system handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FileSystem custom file system handler | |
type FileSystem struct { | |
fs http.FileSystem | |
} | |
// Open opens file | |
func (fs FileSystem) Open(path string) (http.File, error) { | |
f, err := fs.fs.Open(path) | |
if err != nil { | |
return nil, err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"strings" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List lists data and paging the result | |
func (crud *CRUD) List(pageID, perPage int64) ([]interface{}, error) { | |
offset := (pageID - 1) * perPage | |
rows, err := crud.Config.DB.Queryx(crud.Config.sqlCRUDList, offset, perPage) | |
if err != nil { | |
return nil, errors.Wrap(err, "error crud list") | |
} | |
defer rows.Close() | |
result := []interface{}{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (crud *CRUD) registerL() gomHTTP.ServerRoute { | |
// build list sql | |
fields := crud.Config.listFields | |
if len(fields) == 0 { | |
// allow update all fields | |
fields = crud.Config.fields | |
} | |
fieldNames := make([]string, len(fields)) | |
for i, field := range fields { | |
fieldNames[i] = field.name |
NewerOlder