Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 74e56f55d6 | |||
| ae4020fdcf | |||
| 2c1ceed904 | |||
| 458ef03a7c | |||
| 89e38791bf | 
@@ -17,14 +17,6 @@ func MD5(b []byte) string {
 | 
				
			|||||||
	return hex.EncodeToString(hash[:])
 | 
						return hex.EncodeToString(hash[:])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
func MD5Int(b []byte) uint64 {
 | 
					 | 
				
			||||||
	n := new(big.Int)
 | 
					 | 
				
			||||||
	n.SetString(MD5(b), 16)
 | 
					 | 
				
			||||||
	return n.Uint64()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// SHA256 Sum256 is generally preferred over md5.hash due to its superior security and resistance to collision attacks
 | 
					// SHA256 Sum256 is generally preferred over md5.hash due to its superior security and resistance to collision attacks
 | 
				
			||||||
func SHA256(b []byte) string {
 | 
					func SHA256(b []byte) string {
 | 
				
			||||||
	hash := sha256.Sum256(b)
 | 
						hash := sha256.Sum256(b)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										89
									
								
								date/date.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								date/date.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
				
			|||||||
 | 
					// Copyright 2025 Patial Tech (Ankit Patial).
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
 | 
				
			||||||
 | 
					// See http://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ParseISODate ISO date format to utc
 | 
				
			||||||
 | 
					func ParseISODate(dt string) (time.Time, error) {
 | 
				
			||||||
 | 
						d, err := time.Parse(time.RFC3339, dt)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return time.Time{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return d.UTC(), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func CountWorkingDays(from, end time.Time) int {
 | 
				
			||||||
 | 
						workingDays := 0
 | 
				
			||||||
 | 
						start := from // from.AddDate(0, 0, 1)
 | 
				
			||||||
 | 
						for d := start; d.Before(end) || d.Equal(end); d = d.AddDate(0, 0, 1) {
 | 
				
			||||||
 | 
							weekday := d.Weekday()
 | 
				
			||||||
 | 
							if weekday != time.Saturday && weekday != time.Sunday {
 | 
				
			||||||
 | 
								workingDays++
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return workingDays
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func StartOfDay(date time.Time) time.Time {
 | 
				
			||||||
 | 
						year, month, day := date.Date()
 | 
				
			||||||
 | 
						return time.Date(year, month, day, 0, 0, 0, 0, date.Location())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EndOfDay(date time.Time) time.Time {
 | 
				
			||||||
 | 
						year, month, day := date.Date()
 | 
				
			||||||
 | 
						return time.Date(year, month, day, 23, 59, 59, 0, date.Location())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func StartOfMonth(date time.Time) time.Time {
 | 
				
			||||||
 | 
						year, month, _ := date.Date()
 | 
				
			||||||
 | 
						return time.Date(year, month, 1, 0, 0, 0, 0, date.Location())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EndOfMonth(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return EndOfDay(date.AddDate(0, 1, -date.Day()))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func StartOfWeek(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return StartOfDay(date.AddDate(0, 0, int(time.Sunday)-int(date.Weekday())))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EndOfWeek(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return EndOfDay(date.AddDate(0, 0, int(time.Saturday-date.Weekday())))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func StartOfYear(date time.Time) time.Time {
 | 
				
			||||||
 | 
						year, _, _ := date.Date()
 | 
				
			||||||
 | 
						return time.Date(year, 1, 1, 0, 0, 0, 0, date.Location())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EndOfYear(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return EndOfDay(date.AddDate(0, int(time.December-date.Month())+1, -date.Day()))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LastWeek(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return date.AddDate(0, 0, -7)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LastMonth(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return date.AddDate(0, -1, 0)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SubtractMonths(date time.Time, m int) time.Time {
 | 
				
			||||||
 | 
						return date.AddDate(0, -m, 0)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SubtractDays(date time.Time, d int) time.Time {
 | 
				
			||||||
 | 
						return date.AddDate(0, 0, -d)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SubtractAYear(date time.Time) time.Time {
 | 
				
			||||||
 | 
						return date.AddDate(-1, 0, 0)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										85
									
								
								dotenv/assign.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								dotenv/assign.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					package dotenv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"log/slog"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Assign env tag matching values from envMap
 | 
				
			||||||
 | 
					func Assign[T any](to *T, envMap map[string]string) error {
 | 
				
			||||||
 | 
						if to == nil {
 | 
				
			||||||
 | 
							slog.Warn(" arg 'to' is nil")
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(envMap) == 0 {
 | 
				
			||||||
 | 
							slog.Warn(" envMap is nil")
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						val := reflect.Indirect(reflect.ValueOf(to))
 | 
				
			||||||
 | 
						name := val.Type().Name()
 | 
				
			||||||
 | 
						for i := range val.NumField() {
 | 
				
			||||||
 | 
							f := val.Type().Field(i)
 | 
				
			||||||
 | 
							tag := f.Tag.Get("env")
 | 
				
			||||||
 | 
							if tag == "" {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var v string
 | 
				
			||||||
 | 
							var ok bool
 | 
				
			||||||
 | 
							if multiTag := strings.Split(tag, ","); len(multiTag) > 1 {
 | 
				
			||||||
 | 
								// multi tags like env:"DB_URL,PG_DB_URL"
 | 
				
			||||||
 | 
								for _, mt := range multiTag {
 | 
				
			||||||
 | 
									if v, ok = envMap[strings.TrimSpace(mt)]; ok {
 | 
				
			||||||
 | 
										break
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								v, ok = envMap[tag]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !ok {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							field := val.FieldByName(f.Name)
 | 
				
			||||||
 | 
							if !field.IsValid() {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch f.Type.Kind() {
 | 
				
			||||||
 | 
							case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
 | 
				
			||||||
 | 
								if v, err := strconv.ParseInt(v, 10, 64); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									field.SetInt(v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case reflect.Float32, reflect.Float64:
 | 
				
			||||||
 | 
								if v, err := strconv.ParseFloat(v, 10); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									field.SetFloat(v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case reflect.Bool:
 | 
				
			||||||
 | 
								if strings.EqualFold(v, "true") {
 | 
				
			||||||
 | 
									field.SetBool(true)
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									field.SetBool(false)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								field.SetString(v)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if name == "" {
 | 
				
			||||||
 | 
								slog.Info("override value from env", "field", f.Name)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								slog.Info("override value from env", "type", name, "field", f.Name)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -23,7 +23,7 @@ const (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func parseBytes(src []byte, out map[string]string) error {
 | 
					func parseBytes(src []byte, out map[string]string) error {
 | 
				
			||||||
	src = bytes.Replace(src, []byte("\r\n"), []byte("\n"), -1)
 | 
						src = bytes.ReplaceAll(src, []byte("\r\n"), []byte("\n"))
 | 
				
			||||||
	cutset := src
 | 
						cutset := src
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		cutset = getStatementStart(cutset)
 | 
							cutset = getStatementStart(cutset)
 | 
				
			||||||
@@ -76,8 +76,8 @@ func getStatementStart(src []byte) []byte {
 | 
				
			|||||||
func locateKeyName(src []byte) (key string, cutset []byte, err error) {
 | 
					func locateKeyName(src []byte) (key string, cutset []byte, err error) {
 | 
				
			||||||
	// trim "export" and space at beginning
 | 
						// trim "export" and space at beginning
 | 
				
			||||||
	src = bytes.TrimLeftFunc(src, isSpace)
 | 
						src = bytes.TrimLeftFunc(src, isSpace)
 | 
				
			||||||
	if bytes.HasPrefix(src, []byte(exportPrefix)) {
 | 
						if after, ok := bytes.CutPrefix(src, []byte(exportPrefix)); ok {
 | 
				
			||||||
		trimmed := bytes.TrimPrefix(src, []byte(exportPrefix))
 | 
							trimmed := after
 | 
				
			||||||
		if bytes.IndexFunc(trimmed, isSpace) == 0 {
 | 
							if bytes.IndexFunc(trimmed, isSpace) == 0 {
 | 
				
			||||||
			src = bytes.TrimLeftFunc(trimmed, isSpace)
 | 
								src = bytes.TrimLeftFunc(trimmed, isSpace)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,14 +22,17 @@ func Read(dir string, filenames ...string) (envMap map[string]string, err error)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for _, filename := range filenames {
 | 
						for _, filename := range filenames {
 | 
				
			||||||
		slog.Info("read .env", slog.String("file", filepath.Join(dir, filename)))
 | 
							slog.Info("read .env", slog.String("file", filepath.Join(dir, filename)))
 | 
				
			||||||
		individualEnvMap, individualErr := readFile(filepath.Join(dir, filename))
 | 
							m, er := readFile(filepath.Join(dir, filename))
 | 
				
			||||||
 | 
							if er != nil {
 | 
				
			||||||
		if individualErr != nil {
 | 
								if os.IsNotExist(er) {
 | 
				
			||||||
			err = individualErr
 | 
									slog.Info(".env not found", slog.String("file", filename))
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								err = er
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		maps.Copy(envMap, individualEnvMap)
 | 
							maps.Copy(envMap, m)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,7 +56,7 @@ func doubleQuoteEscape(line string) string {
 | 
				
			|||||||
		if c == '\r' {
 | 
							if c == '\r' {
 | 
				
			||||||
			toReplace = `\r`
 | 
								toReplace = `\r`
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		line = strings.Replace(line, string(c), toReplace, -1)
 | 
							line = strings.ReplaceAll(line, string(c), toReplace)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return line
 | 
						return line
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,11 +17,12 @@ import (
 | 
				
			|||||||
// SMTP mailer
 | 
					// SMTP mailer
 | 
				
			||||||
type SMTP struct {
 | 
					type SMTP struct {
 | 
				
			||||||
	Host     string
 | 
						Host     string
 | 
				
			||||||
	Port     int
 | 
					 | 
				
			||||||
	Username string
 | 
						Username string
 | 
				
			||||||
	Password string
 | 
						Password string
 | 
				
			||||||
	// Domain name for smtp
 | 
						// Domain name for smtp
 | 
				
			||||||
	Domain string
 | 
						Domain string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Port int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (t SMTP) Send(msg *Message) error {
 | 
					func (t SMTP) Send(msg *Message) error {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,21 +1,20 @@
 | 
				
			|||||||
module code.patial.tech/go/appcore
 | 
					module code.patial.tech/go/appcore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.24
 | 
					go 1.25
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/go-playground/validator/v10 v10.26.0
 | 
						github.com/go-playground/validator/v10 v10.27.0
 | 
				
			||||||
	github.com/golang-jwt/jwt/v5 v5.2.2
 | 
						github.com/golang-jwt/jwt/v5 v5.3.0
 | 
				
			||||||
	github.com/google/uuid v1.6.0
 | 
						github.com/google/uuid v1.6.0
 | 
				
			||||||
	github.com/sqids/sqids-go v0.4.1
 | 
						github.com/sqids/sqids-go v0.4.1
 | 
				
			||||||
	golang.org/x/crypto v0.39.0
 | 
						golang.org/x/crypto v0.42.0
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/gabriel-vasile/mimetype v1.4.8 // indirect
 | 
						github.com/gabriel-vasile/mimetype v1.4.10 // indirect
 | 
				
			||||||
	github.com/go-playground/locales v0.14.1 // indirect
 | 
						github.com/go-playground/locales v0.14.1 // indirect
 | 
				
			||||||
	github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
						github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
				
			||||||
	github.com/leodido/go-urn v1.4.0 // indirect
 | 
						github.com/leodido/go-urn v1.4.0 // indirect
 | 
				
			||||||
	golang.org/x/net v0.34.0 // indirect
 | 
						golang.org/x/sys v0.36.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.33.0 // indirect
 | 
						golang.org/x/text v0.29.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.26.0 // indirect
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,17 +1,17 @@
 | 
				
			|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
					github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
 | 
					github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
 | 
				
			||||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
 | 
					github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 | 
					github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
					github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
				
			||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 | 
					github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 | 
				
			||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 | 
					github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
 | 
					github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
 | 
				
			||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 | 
					github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
 | 
					github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
 | 
				
			||||||
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
 | 
					github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
 | 
				
			||||||
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
 | 
					github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
 | 
				
			||||||
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
 | 
					github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
 | 
				
			||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
					github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
				
			||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
					github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
				
			||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
 | 
					github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
 | 
				
			||||||
@@ -22,13 +22,11 @@ github.com/sqids/sqids-go v0.4.1 h1:eQKYzmAZbLlRwHeHYPF35QhgxwZHLnlmVj9AkIj/rrw=
 | 
				
			|||||||
github.com/sqids/sqids-go v0.4.1/go.mod h1:EMwHuPQgSNFS0A49jESTfIQS+066XQTVhukrzEPScl8=
 | 
					github.com/sqids/sqids-go v0.4.1/go.mod h1:EMwHuPQgSNFS0A49jESTfIQS+066XQTVhukrzEPScl8=
 | 
				
			||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 | 
					github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 | 
				
			||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 | 
					github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 | 
				
			||||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
 | 
					golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
 | 
				
			||||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
 | 
					golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
 | 
				
			||||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
 | 
					golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
 | 
				
			||||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
 | 
					golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
 | 
				
			||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
 | 
					golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
 | 
				
			||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 | 
					golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
 | 
				
			||||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
 | 
					 | 
				
			||||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
 | 
					 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										46
									
								
								gz/gz.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								gz/gz.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					// Copyright 2025 Patial Tech (Ankit Patial).
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
 | 
				
			||||||
 | 
					// See http://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package gz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"compress/gzip"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Zip(data []byte) ([]byte, error) {
 | 
				
			||||||
 | 
						var b bytes.Buffer
 | 
				
			||||||
 | 
						gz := gzip.NewWriter(&b)
 | 
				
			||||||
 | 
						if _, err := gz.Write(data); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := gz.Flush(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := gz.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.Bytes(), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func UnZip(data []byte) ([]byte, error) {
 | 
				
			||||||
 | 
						b := bytes.NewBuffer(data)
 | 
				
			||||||
 | 
						var r io.Reader
 | 
				
			||||||
 | 
						r, err := gzip.NewReader(b)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var resB bytes.Buffer
 | 
				
			||||||
 | 
						if _, err := resB.ReadFrom(r); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return resB.Bytes(), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -22,7 +22,7 @@ func Str(v string) *string {
 | 
				
			|||||||
	return &v
 | 
						return &v
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NumStr(v *string) string {
 | 
					func GetStr(v *string) string {
 | 
				
			||||||
	if v == nil {
 | 
						if v == nil {
 | 
				
			||||||
		return ""
 | 
							return ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -39,7 +39,7 @@ func StrTrim(v *string) *string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type N interface {
 | 
					type N interface {
 | 
				
			||||||
	uint8 | int8 | uint16 | int16 | uint | int | uint32 | int32 | uint64 | int64 | float32 | float64
 | 
						uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | uint | int | float32 | float64
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Number[T N](v T) *T {
 | 
					func Number[T N](v T) *T {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,13 +14,16 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Pager struct {
 | 
					type Pager struct {
 | 
				
			||||||
	Search      string
 | 
						OrderBy  *string `json:"orderBy"`
 | 
				
			||||||
	OrderBy     *string `json:"orderBy"`
 | 
						OrderAsc *bool   `json:"orderAsc"`
 | 
				
			||||||
	OrderAsc    *bool   `json:"orderAsc"`
 | 
					
 | 
				
			||||||
	Page        int     `json:"page"`
 | 
						Search string
 | 
				
			||||||
	Size        int     `json:"size"`
 | 
					
 | 
				
			||||||
	Total       int     `json:"total"`
 | 
						Page  int `json:"page"`
 | 
				
			||||||
	TotalNeeded bool    `json:"-"`
 | 
						Size  int `json:"size"`
 | 
				
			||||||
 | 
						Total int `json:"total"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						TotalNeeded bool `json:"-"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (i *Pager) HasSearch() bool {
 | 
					func (i *Pager) HasSearch() bool {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ import (
 | 
				
			|||||||
func Map(obj any) map[string]any {
 | 
					func Map(obj any) map[string]any {
 | 
				
			||||||
	result := make(map[string]any)
 | 
						result := make(map[string]any)
 | 
				
			||||||
	val := reflect.ValueOf(obj)
 | 
						val := reflect.ValueOf(obj)
 | 
				
			||||||
	if val.Kind() == reflect.Ptr {
 | 
						if val.Kind() == reflect.Pointer {
 | 
				
			||||||
		val = val.Elem()
 | 
							val = val.Elem()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user