repo
stringlengths
6
47
file_url
stringlengths
77
269
file_path
stringlengths
5
186
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-07 08:35:43
2026-01-07 08:55:24
truncated
bool
2 classes
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/rangereader_test.go
core/filex/rangereader_test.go
package filex import ( "os" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" ) func TestRangeReader(t *testing.T) { const text = `hello world` file, err := fs.TempFileWithText(text) assert.Nil(t, err) defer func() { file.Close() os.Remove(file.Name()) }() reader :=...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/file.go
core/filex/file.go
package filex import ( "io" "os" ) const bufSize = 1024 // FirstLine returns the first line of the file. func FirstLine(filename string) (string, error) { file, err := os.Open(filename) if err != nil { return "", err } defer file.Close() return firstLine(file) } // LastLine returns the last line of the fi...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/rangereader.go
core/filex/rangereader.go
package filex import ( "errors" "os" ) // errExceedFileSize indicates that the file size is exceeded. var errExceedFileSize = errors.New("exceed file size") // A RangeReader is used to read a range of content from a file. type RangeReader struct { file *os.File start int64 stop int64 } // NewRangeReader retu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/file_test.go
core/filex/file_test.go
package filex import ( "os" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" ) const ( longLine = `Quid securi etiam tamquam eu fugiat nulla pariatur. Nec dubitamus multa iter quae et nos invenerat. Non equidem invideo, miror magis posuere velit aliquet. Integer legenti...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/lookup_test.go
core/filex/lookup_test.go
package filex import ( "os" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" ) func TestSplitLineChunks(t *testing.T) { const text = `first line second line third line fourth line fifth line sixth line seventh line ` fp, err := fs.TempFileWithText(text) assert.Nil(t, err) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/lookup.go
core/filex/lookup.go
package filex import ( "io" "os" ) // OffsetRange represents a content block of a file. type OffsetRange struct { File string Start int64 Stop int64 } // SplitLineChunks splits file into chunks. // The whole line are guaranteed to be split in the same chunk. func SplitLineChunks(filename string, chunks int) (...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/progressscanner_test.go
core/filex/progressscanner_test.go
package filex import ( "strings" "testing" "github.com/stretchr/testify/assert" "gopkg.in/cheggaaa/pb.v1" ) func TestProgressScanner(t *testing.T) { const text = "hello, world" bar := pb.New(100) var builder strings.Builder builder.WriteString(text) scanner := NewProgressScanner(&mockedScanner{builder: &bui...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/filex/progressscanner.go
core/filex/progressscanner.go
package filex import "gopkg.in/cheggaaa/pb.v1" type ( // A Scanner is used to read lines. Scanner interface { // Scan checks if it has remaining to read. Scan() bool // Text returns next line. Text() string } progressScanner struct { Scanner bar *pb.ProgressBar } ) // NewProgressScanner returns a S...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/sysx/automaxprocs.go
core/sysx/automaxprocs.go
package sysx import "go.uber.org/automaxprocs/maxprocs" // Automatically set GOMAXPROCS to match Linux container CPU quota. func init() { maxprocs.Set(maxprocs.Logger(nil)) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/sysx/host.go
core/sysx/host.go
package sysx import ( "os" "github.com/zeromicro/go-zero/core/stringx" ) var hostname string func init() { var err error hostname, err = os.Hostname() if err != nil { hostname = stringx.RandId() } } // Hostname returns the name of the host, if no hostname, a random id is returned. func Hostname() string { ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/sysx/host_test.go
core/sysx/host_test.go
package sysx import ( "testing" "github.com/stretchr/testify/assert" ) func TestHostname(t *testing.T) { assert.True(t, len(Hostname()) > 0) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/service/servicegroup_test.go
core/service/servicegroup_test.go
package service import ( "sync" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/proc" ) var ( number = 1 mutex sync.Mutex done = make(chan struct{}) ) func TestServiceGroup(t *testing.T) { multipliers := []int{2, 3, 5, 7} want := 1 group := NewServiceGroup() for _, m...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/service/serviceconf.go
core/service/serviceconf.go
package service import ( "github.com/zeromicro/go-zero/core/load" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/prometheus" "github.com/zeromicro/go-zero/core/stat" "github.com/zeromicro/go-zero/core/trace" "github.com/zeromicro/go-zero/inte...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/service/servicegroup.go
core/service/servicegroup.go
package service import ( "sync" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/threading" ) type ( // Starter is the interface wraps the Start method. Starter interface { Start() } // Stopper is the interface wraps the Stop method. Sto...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/service/serviceconf_test.go
core/service/serviceconf_test.go
package service import ( "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/internal/devserver" ) func TestServiceConf(t *testing.T) { c := ServiceConf{ Name: "foo", Log: logx.LogConf{ Mode: "console", }, Mode: "dev", DevServer: dev...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/lang/lang_test.go
core/lang/lang_test.go
package lang import ( "encoding/json" "errors" "reflect" "testing" "github.com/stretchr/testify/assert" ) func TestRepr(t *testing.T) { var ( f32 float32 = 1.1 f64 = 2.2 i8 int8 = 1 i16 int16 = 2 i32 int32 = 3 i64 int64 = 4 u8 uint8 = 5 u16 uint16 = 6 u32 uint32 = 7 u...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/lang/lang.go
core/lang/lang.go
package lang import ( "fmt" "reflect" "strconv" ) // Placeholder is a placeholder object that can be used globally. var Placeholder PlaceholderType type ( // AnyType can be used to hold any type. AnyType = any // PlaceholderType represents a placeholder type. PlaceholderType = struct{} ) // Repr returns the ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/read_test.go
core/iox/read_test.go
package iox import ( "bytes" "io" "os" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" "github.com/zeromicro/go-zero/core/stringx" ) func TestReadText(t *testing.T) { tests := []struct { input string expect string }{ { input: `a`, expect: `a`, },...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/bufferpool_test.go
core/iox/bufferpool_test.go
package iox import ( "bytes" "testing" "github.com/stretchr/testify/assert" ) func TestBufferPool(t *testing.T) { capacity := 1024 pool := NewBufferPool(capacity) pool.Put(bytes.NewBuffer(make([]byte, 0, 2*capacity))) assert.True(t, pool.Get().Cap() <= capacity) } func TestBufferPool_Put(t *testing.T) { t.R...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/tee.go
core/iox/tee.go
package iox import "io" // LimitTeeReader returns a Reader that writes up to n bytes to w what it reads from r. // First n bytes reads from r performed through it are matched with // corresponding writes to w. There is no internal buffering - // the write must complete before the first n bytes read completes. // Any ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/nopcloser.go
core/iox/nopcloser.go
package iox import "io" type nopCloser struct { io.Writer } func (nopCloser) Close() error { return nil } // NopCloser returns an io.WriteCloser that does nothing on calling Close. func NopCloser(w io.Writer) io.WriteCloser { return nopCloser{w} }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/pipe_test.go
core/iox/pipe_test.go
package iox import ( "testing" "github.com/stretchr/testify/assert" ) func TestRedirectInOut(t *testing.T) { restore, err := RedirectInOut() assert.Nil(t, err) defer restore() }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/textfile.go
core/iox/textfile.go
package iox import ( "bytes" "errors" "io" "os" ) const bufSize = 32 * 1024 // CountLines returns the number of lines in the file. func CountLines(file string) (int, error) { f, err := os.Open(file) if err != nil { return 0, err } defer f.Close() var noEol bool buf := make([]byte, bufSize) count := 0 ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/bufferpool.go
core/iox/bufferpool.go
package iox import ( "bytes" "sync" ) // A BufferPool is a pool to buffer bytes.Buffer objects. type BufferPool struct { capability int pool *sync.Pool } // NewBufferPool returns a BufferPool. func NewBufferPool(capability int) *BufferPool { return &BufferPool{ capability: capability, pool: &sync.Pool...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/nopcloser_test.go
core/iox/nopcloser_test.go
package iox import ( "testing" "github.com/stretchr/testify/assert" ) func TestNopCloser(t *testing.T) { closer := NopCloser(nil) assert.NoError(t, closer.Close()) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/read.go
core/iox/read.go
package iox import ( "bufio" "bytes" "io" "os" "strings" ) type ( textReadOptions struct { keepSpace bool withoutBlanks bool omitPrefix string } // TextReadOption defines the method to customize the text reading functions. TextReadOption func(*textReadOptions) ) // DupReadCloser returns two io...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/textlinescanner.go
core/iox/textlinescanner.go
package iox import ( "bufio" "errors" "io" "strings" ) // A TextLineScanner is a scanner that can scan lines from the given reader. type TextLineScanner struct { reader *bufio.Reader hasNext bool line string err error } // NewTextLineScanner returns a TextLineScanner with the given reader. func NewTe...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/textlinescanner_test.go
core/iox/textlinescanner_test.go
package iox import ( "strings" "testing" "testing/iotest" "github.com/stretchr/testify/assert" ) func TestScanner(t *testing.T) { const val = `1 2 3 4` reader := strings.NewReader(val) scanner := NewTextLineScanner(reader) var lines []string for scanner.Scan() { line, err := scanner.Line() assert.Nil(t,...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/textfile_test.go
core/iox/textfile_test.go
package iox import ( "os" "testing" "github.com/stretchr/testify/assert" ) func TestCountLines(t *testing.T) { const val = `1 2 3 4` file, err := os.CreateTemp(os.TempDir(), "test-") if err != nil { t.Fatal(err) } defer os.Remove(file.Name()) file.WriteString(val) file.Close() lines, err := CountLines(...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/tee_test.go
core/iox/tee_test.go
package iox import ( "bytes" "io" "testing" "github.com/stretchr/testify/assert" ) func TestLimitTeeReader(t *testing.T) { limit := int64(4) src := []byte("hello, world") dst := make([]byte, len(src)) rb := bytes.NewBuffer(src) wb := new(bytes.Buffer) r := LimitTeeReader(rb, wb, limit) if n, err := io.Rea...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/iox/pipe.go
core/iox/pipe.go
package iox import "os" // RedirectInOut redirects stdin to r, stdout to w, and callers need to call restore afterward. func RedirectInOut() (restore func(), err error) { var r, w *os.File r, w, err = os.Pipe() if err != nil { return } ow := os.Stdout os.Stdout = w or := os.Stdin os.Stdin = r restore = fu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/rescue/recover.go
core/rescue/recover.go
package rescue import ( "context" "runtime/debug" "github.com/zeromicro/go-zero/core/logx" ) // Recover is used with defer to do cleanup on panics. // Use it like: // // defer Recover(func() {}) func Recover(cleanups ...func()) { for _, cleanup := range cleanups { cleanup() } if p := recover(); p != nil { ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/rescue/recover_test.go
core/rescue/recover_test.go
package rescue import ( "context" "sync/atomic" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/logx" ) func init() { logx.Disable() } func TestRescue(t *testing.T) { var count int32 assert.NotPanics(t, func() { defer Recover(func() { atomic.AddInt32(&count, 2) }, fu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/nopbreaker_test.go
core/breaker/nopbreaker_test.go
package breaker import ( "context" "errors" "testing" "github.com/stretchr/testify/assert" ) func TestNopBreaker(t *testing.T) { b := NopBreaker() assert.Equal(t, nopBreakerName, b.Name()) _, err := b.Allow() assert.Nil(t, err) p, err := b.AllowCtx(context.Background()) assert.Nil(t, err) p.Accept() for ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/bucket.go
core/breaker/bucket.go
package breaker const ( success = iota fail drop ) // bucket defines the bucket that holds sum and num of additions. type bucket struct { Sum int64 Success int64 Failure int64 Drop int64 } func (b *bucket) Add(v int64) { switch v { case fail: b.fail() case drop: b.drop() default: b.succeed() ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/breakers_test.go
core/breaker/breakers_test.go
package breaker import ( "context" "errors" "fmt" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/stat" ) func init() { stat.SetReporter(nil) } func TestBreakersDo(t *testing.T) { assert.Nil(t, Do("any", func() error { return nil })) errDummy := errors.New("any") asse...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/googlebreaker.go
core/breaker/googlebreaker.go
package breaker import ( "time" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/core/mathx" "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/timex" ) const ( // 250ms for bucket duration window = time.Second * 10 buckets = 40 forc...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/breakers.go
core/breaker/breakers.go
package breaker import ( "context" "sync" ) var ( lock sync.RWMutex breakers = make(map[string]Breaker) ) // Do calls Breaker.Do on the Breaker with given name. func Do(name string, req func() error) error { return do(name, func(b Breaker) error { return b.Do(req) }) } // DoCtx calls Breaker.DoCtx on th...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/bucket_test.go
core/breaker/bucket_test.go
package breaker import ( "testing" "github.com/stretchr/testify/assert" ) func TestBucketAdd(t *testing.T) { b := &bucket{} // Test succeed b.Add(0) // Using 0 for success assert.Equal(t, int64(1), b.Sum, "Sum should be incremented") assert.Equal(t, int64(1), b.Success, "Success should be incremented") asse...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/breaker_test.go
core/breaker/breaker_test.go
package breaker import ( "context" "errors" "fmt" "strconv" "strings" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/stat" ) func init() { stat.SetReporter(nil) } func TestCircuitBreaker_Allow(t *testing.T) { t.Run("allow", func(t *testing.T) { b := NewBreaker(...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/nopbreaker.go
core/breaker/nopbreaker.go
package breaker import "context" const nopBreakerName = "nopBreaker" type nopBreaker struct{} // NopBreaker returns a breaker that never trigger breaker circuit. func NopBreaker() Breaker { return nopBreaker{} } func (b nopBreaker) Name() string { return nopBreakerName } func (b nopBreaker) Allow() (Promise, er...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/breaker.go
core/breaker/breaker.go
package breaker import ( "context" "errors" "fmt" "strings" "sync" "time" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/stat" "github.com/zeromicro/go-zero/core/stringx" ) const numHistoryReasons = 5 // ErrServiceUnavailable is returned when the Breaker state is open. var ErrS...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/breaker/googlebreaker_test.go
core/breaker/googlebreaker_test.go
package breaker import ( "errors" "math/rand" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/core/mathx" "github.com/zeromicro/go-zero/core/stat" "github.com/zeromicro/go-zero/core/syncx" ) const ( testBuckets = 10 testIn...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/hash/hash.go
core/hash/hash.go
package hash import ( "crypto/md5" "encoding/hex" "github.com/spaolacci/murmur3" ) // Hash returns the hash value of data. func Hash(data []byte) uint64 { return murmur3.Sum64(data) } // Md5 returns the md5 bytes of data. func Md5(data []byte) []byte { digest := md5.New() digest.Write(data) return digest.Sum...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/hash/hash_test.go
core/hash/hash_test.go
package hash import ( "crypto/md5" "fmt" "hash/fnv" "math/big" "testing" "github.com/stretchr/testify/assert" ) const ( text = "hello, world!\n" md5Digest = "910c8bc73110b0cd1bc5d2bcae782511" ) func TestMd5(t *testing.T) { actual := fmt.Sprintf("%x", Md5([]byte(text))) assert.Equal(t, md5Digest, actu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/hash/consistenthash.go
core/hash/consistenthash.go
package hash import ( "fmt" "sort" "strconv" "sync" "github.com/zeromicro/go-zero/core/lang" ) const ( // TopWeight is the top weight that one entry might set. TopWeight = 100 minReplicas = 100 prime = 16777619 ) type ( // Func defines the hash method. Func func(data []byte) uint64 // A Consiste...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/hash/consistenthash_test.go
core/hash/consistenthash_test.go
package hash import ( "fmt" "strconv" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/mathx" ) const ( keySize = 20 requestSize = 1000 ) func BenchmarkConsistentHashGet(b *testing.B) { ch := NewConsistentHash() for i := 0; i < keySize; i++ { ch.Add("localhost:" + str...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/limit/periodlimit_test.go
core/limit/periodlimit_test.go
package limit import ( "testing" "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/core/stores/redis/redistest" ) func TestPeriodLimit_Take(t *testing.T) { testPeriodLimit(t) } func TestPeriodLimit_TakeWithAli...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/limit/periodlimit.go
core/limit/periodlimit.go
package limit import ( "context" _ "embed" "errors" "strconv" "time" "github.com/zeromicro/go-zero/core/stores/redis" ) const ( // Unknown means not initialized state. Unknown = iota // Allowed means allowed state. Allowed // HitQuota means this request exactly hit the quota. HitQuota // OverQuota means...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/limit/tokenlimit_test.go
core/limit/tokenlimit_test.go
package limit import ( "context" "testing" "time" "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/core/stores/redis/redistest" ) func init() { logx.Disable() } fun...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/limit/tokenlimit.go
core/limit/tokenlimit.go
package limit import ( "context" _ "embed" "errors" "fmt" "strconv" "sync" "sync/atomic" "time" "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stores/redis" xrate "golang.org/x/time/rate" ) const ( tokenFormat = "{%s}.tokens" t...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/random_test.go
core/stringx/random_test.go
package stringx import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestRand(t *testing.T) { Seed(time.Now().UnixNano()) assert.True(t, len(Rand()) > 0) assert.True(t, len(RandId()) > 0) const size = 10 assert.True(t, len(Randn(size)) == size) } func BenchmarkRandString(b *testing.B) { f...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/strings_test.go
core/stringx/strings_test.go
package stringx import ( "path" "testing" "github.com/stretchr/testify/assert" ) func TestContainsString(t *testing.T) { cases := []struct { slice []string value string expect bool }{ {[]string{"1"}, "1", true}, {[]string{"1"}, "2", false}, {[]string{"1", "2"}, "1", true}, {[]string{"1", "2"}, "...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/replacer.go
core/stringx/replacer.go
package stringx import ( "sort" "strings" ) // replace more than once to avoid overlapped keywords after replace. // only try 2 times to avoid too many or infinite loops. const replaceTimes = 2 type ( // Replacer interface wraps the Replace method. Replacer interface { Replace(text string) string } replacer...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/trie.go
core/stringx/trie.go
package stringx import "github.com/zeromicro/go-zero/core/lang" const defaultMask = '*' type ( // TrieOption defines the method to customize a Trie. TrieOption func(trie *trieNode) // A Trie is a tree implementation that used to find elements rapidly. Trie interface { Filter(text string) (string, []string, bo...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/node.go
core/stringx/node.go
package stringx type node struct { children map[rune]*node fail *node depth int end bool } func (n *node) add(word string) { chars := []rune(word) if len(chars) == 0 { return } nd := n for i, char := range chars { if nd.children == nil { child := new(node) child.depth = i + 1 nd.chi...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/node_test.go
core/stringx/node_test.go
package stringx import ( "testing" "github.com/stretchr/testify/assert" ) func TestFuzzNodeCase1(t *testing.T) { keywords := []string{ "cs8Zh", "G1OihlVuBz", "K6azS2FBHjI", "DQKvghI4", "l7bA86Sze", "tjBLZhCao", "nEsXmVzP", "cbRh8UE1nO3s", "Wta3R2WcbGP", "jpOIcA", "TtkRr4k9hI", "OKbSo0clAYT...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/replacer_fuzz_test.go
core/stringx/replacer_fuzz_test.go
package stringx import ( "fmt" "math/rand" "strings" "testing" ) func FuzzReplacerReplace(f *testing.F) { keywords := make(map[string]string) for i := 0; i < 20; i++ { keywords[Randn(rand.Intn(10)+5)] = Randn(rand.Intn(5) + 1) } rep := NewReplacer(keywords) printableKeywords := func() string { var buf st...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/strings.go
core/stringx/strings.go
package stringx import ( "errors" "slices" "unicode" "github.com/zeromicro/go-zero/core/lang" ) var ( // ErrInvalidStartPosition is an error that indicates the start position is invalid. ErrInvalidStartPosition = errors.New("start position is invalid") // ErrInvalidStopPosition is an error that indicates the ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/trie_test.go
core/stringx/trie_test.go
package stringx import ( "testing" "github.com/stretchr/testify/assert" ) func TestTrieSimple(t *testing.T) { trie := NewTrie([]string{ "bc", "cd", }) output, keywords, found := trie.Filter("abcd") assert.True(t, found) assert.Equal(t, "a***", output) assert.ElementsMatch(t, []string{"bc", "cd"}, keyword...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/replacer_test.go
core/stringx/replacer_test.go
package stringx import ( "testing" "github.com/stretchr/testify/assert" ) func TestReplacer_Replace(t *testing.T) { mapping := map[string]string{ "一二三四": "1234", "二三": "23", "二": "2", } assert.Equal(t, "零1234五", NewReplacer(mapping).Replace("零一二三四五")) } func TestReplacer_ReplaceJumpMatch(t *testing....
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/random.go
core/stringx/random.go
package stringx import ( crand "crypto/rand" "fmt" "math/rand" "sync" "time" ) const ( letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" letterIdxBits = 6 // 6 bits to represent a letter index idLen = 8 defaultRandLen = 8 letterIdxMask = 1<<letterIdxBits - 1 // All...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stringx/node_fuzz_test.go
core/stringx/node_fuzz_test.go
package stringx import ( "fmt" "math/rand" "strings" "testing" "time" "github.com/stretchr/testify/assert" ) func FuzzNodeFind(f *testing.F) { rand.NewSource(time.Now().UnixNano()) f.Add(10) f.Fuzz(func(t *testing.T, keys int) { str := Randn(rand.Intn(100) + 50) keywords := make(map[string]struct{}) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/delayexecutor.go
core/executors/delayexecutor.go
package executors import ( "sync" "time" "github.com/zeromicro/go-zero/core/threading" ) // A DelayExecutor delays a tasks on given delay interval. type DelayExecutor struct { fn func() delay time.Duration triggered bool lock sync.Mutex } // NewDelayExecutor returns a DelayExecutor with given...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/chunkexecutor.go
core/executors/chunkexecutor.go
package executors import "time" const defaultChunkSize = 1024 * 1024 // 1M type ( // ChunkOption defines the method to customize a ChunkExecutor. ChunkOption func(options *chunkOptions) // A ChunkExecutor is an executor to execute tasks when either requirement meets: // 1. up to given chunk size // 2. flush in...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/lessexecutor.go
core/executors/lessexecutor.go
package executors import ( "time" "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/timex" ) // A LessExecutor is an executor to limit execution once within given time interval. type LessExecutor struct { threshold time.Duration lastTime *syncx.AtomicDuration } // NewLessExecutor re...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/chunkexecutor_test.go
core/executors/chunkexecutor_test.go
package executors import ( "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestChunkExecutor(t *testing.T) { var values []int var lock sync.Mutex executor := NewChunkExecutor(func(items []any) { lock.Lock() values = append(values, len(items)) lock.Unlock() }, WithChunkBytes(10), Wi...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/lessexecutor_test.go
core/executors/lessexecutor_test.go
package executors import ( "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/timex" ) func TestLessExecutor_DoOrDiscard(t *testing.T) { executor := NewLessExecutor(time.Minute) assert.True(t, executor.DoOrDiscard(func() {})) assert.False(t, executor.DoOrDiscard(func() {}...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/periodicalexecutor_test.go
core/executors/periodicalexecutor_test.go
package executors import ( "runtime" "sync" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/timex" ) const threshold = 10 type container struct { interval time.Duration tasks []int execute func(tasks any) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/vars.go
core/executors/vars.go
package executors import "time" const defaultFlushInterval = time.Second // Execute defines the method to execute tasks. type Execute func(tasks []any)
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/bulkexecutor_test.go
core/executors/bulkexecutor_test.go
package executors import ( "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestBulkExecutor(t *testing.T) { var values []int var lock sync.Mutex executor := NewBulkExecutor(func(items []any) { lock.Lock() values = append(values, len(items)) lock.Unlock() }, WithBulkTasks(10), WithB...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/bulkexecutor.go
core/executors/bulkexecutor.go
package executors import "time" const defaultBulkTasks = 1000 type ( // BulkOption defines the method to customize a BulkExecutor. BulkOption func(options *bulkOptions) // A BulkExecutor is an executor that can execute tasks on either requirement meets: // 1. up to given size of tasks // 2. flush interval time...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/delayexecutor_test.go
core/executors/delayexecutor_test.go
package executors import ( "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" ) func TestDelayExecutor(t *testing.T) { var count int32 ex := NewDelayExecutor(func() { atomic.AddInt32(&count, 1) }, time.Millisecond*10) for i := 0; i < 100; i++ { ex.Trigger() } time.Sleep(time.Millisecon...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/executors/periodicalexecutor.go
core/executors/periodicalexecutor.go
package executors import ( "reflect" "sync" "sync/atomic" "time" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/threading" "github.com/zeromicro/go-zero/core/timex" ) const idleRound = 10 type ( ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/atomicerror.go
core/errorx/atomicerror.go
package errorx import "sync/atomic" // AtomicError defines an atomic error. type AtomicError struct { err atomic.Value // error } // Set sets the error. func (ae *AtomicError) Set(err error) { if err != nil { ae.err.Store(err) } } // Load returns the error. func (ae *AtomicError) Load() error { if v := ae.err...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/callchain_test.go
core/errorx/callchain_test.go
package errorx import ( "errors" "testing" "github.com/stretchr/testify/assert" ) func TestChain(t *testing.T) { errDummy := errors.New("dummy") assert.Nil(t, Chain(func() error { return nil }, func() error { return nil })) assert.Equal(t, errDummy, Chain(func() error { return errDummy }, func() error...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/wrap_test.go
core/errorx/wrap_test.go
package errorx import ( "errors" "testing" "github.com/stretchr/testify/assert" ) func TestWrap(t *testing.T) { assert.Nil(t, Wrap(nil, "test")) assert.Equal(t, "foo: bar", Wrap(errors.New("bar"), "foo").Error()) err := errors.New("foo") assert.True(t, errors.Is(Wrap(err, "bar"), err)) } func TestWrapf(t *t...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/callchain.go
core/errorx/callchain.go
package errorx // Chain runs funs one by one until an error occurred. func Chain(fns ...func() error) error { for _, fn := range fns { if err := fn(); err != nil { return err } } return nil }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/check.go
core/errorx/check.go
package errorx import "errors" // In checks if the given err is one of errs. func In(err error, errs ...error) bool { for _, each := range errs { if errors.Is(err, each) { return true } } return false }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/atomicerror_test.go
core/errorx/atomicerror_test.go
package errorx import ( "errors" "sync" "sync/atomic" "testing" "github.com/stretchr/testify/assert" ) var errDummy = errors.New("hello") func TestAtomicError(t *testing.T) { var err AtomicError err.Set(errDummy) assert.Equal(t, errDummy, err.Load()) } func TestAtomicErrorSetNil(t *testing.T) { var ( er...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/batcherror.go
core/errorx/batcherror.go
package errorx import ( "errors" "sync" ) // BatchError is an error that can hold multiple errors. type BatchError struct { errs []error lock sync.RWMutex } // Add adds one or more non-nil errors to the BatchError instance. func (be *BatchError) Add(errs ...error) { be.lock.Lock() defer be.lock.Unlock() for ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/wrap.go
core/errorx/wrap.go
package errorx import "fmt" // Wrap returns an error that wraps err with given message. func Wrap(err error, message string) error { if err == nil { return nil } return fmt.Errorf("%s: %w", message, err) } // Wrapf returns an error that wraps err with given format and args. func Wrapf(err error, format string,...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/check_test.go
core/errorx/check_test.go
package errorx import ( "errors" "testing" ) func TestIn(t *testing.T) { err1 := errors.New("error 1") err2 := errors.New("error 2") err3 := errors.New("error 3") tests := []struct { name string err error errs []error want bool }{ { name: "Error matches one of the errors in the list", err: e...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/errorx/batcherror_test.go
core/errorx/batcherror_test.go
package errorx import ( "errors" "fmt" "sync" "testing" "github.com/stretchr/testify/assert" ) const ( err1 = "first error" err2 = "second error" ) func TestBatchErrorNil(t *testing.T) { var batch BatchError assert.Nil(t, batch.Err()) assert.False(t, batch.NotNil()) batch.Add(nil) assert.Nil(t, batch.Er...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/postgres/postgresql.go
core/stores/postgres/postgresql.go
package postgres import ( // imports the driver, don't remove this comment, golint requires. _ "github.com/jackc/pgx/v5/stdlib" "github.com/zeromicro/go-zero/core/stores/sqlx" ) const postgresDriverName = "pgx" // New returns a postgres connection. func New(datasource string, opts ...sqlx.SqlOption) sqlx.SqlConn...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/postgres/postgresql_test.go
core/stores/postgres/postgresql_test.go
package postgres import ( "testing" "github.com/stretchr/testify/assert" ) func TestPostgreSql(t *testing.T) { assert.NotNil(t, New("postgre")) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/builder/builder.go
core/stores/builder/builder.go
package builder import ( "fmt" "reflect" "strings" ) const dbTag = "db" // RawFieldNames converts golang struct field into slice string. func RawFieldNames(in any, postgreSql ...bool) []string { out := make([]string, 0) v := reflect.ValueOf(in) if v.Kind() == reflect.Ptr { v = v.Elem() } var pg bool if l...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/builder/builder_test.go
core/stores/builder/builder_test.go
package builder import ( "testing" "github.com/stretchr/testify/assert" ) type mockedUser struct { ID string `db:"id" json:"id,omitempty"` UserName string `db:"user_name" json:"userName,omitempty"` Sex int `db:"sex" json:"sex,omitempty"` UUID string `db:"uuid" uuid:"uuid,omitempty"` Age ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cacheopt_test.go
core/stores/cache/cacheopt_test.go
package cache import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestCacheOptions(t *testing.T) { t.Run("default options", func(t *testing.T) { o := newOptions() assert.Equal(t, defaultExpiry, o.Expiry) assert.Equal(t, defaultNotFoundExpiry, o.NotFoundExpiry) }) t.Run("with expiry", f...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cacheconf.go
core/stores/cache/cacheconf.go
package cache // CacheConf is an alias of ClusterConf. type CacheConf = ClusterConf
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cache.go
core/stores/cache/cache.go
package cache import ( "context" "errors" "fmt" "log" "time" "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/hash" "github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/core/syncx" ) type ( // Cache interface is used to define the cache implementation....
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cache_test.go
core/stores/cache/cache_test.go
package cache import ( "context" "encoding/json" "errors" "fmt" "math" "strconv" "testing" "time" "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/hash" "github.com/zeromicro/go-zero/core/stores/redis" "...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/config.go
core/stores/cache/config.go
package cache import "github.com/zeromicro/go-zero/core/stores/redis" type ( // A ClusterConf is the config of a redis cluster that used as cache. ClusterConf []NodeConf // A NodeConf is the config of a redis node that used as cache. NodeConf struct { redis.RedisConf Weight int `json:",default=100"` } )
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cachestat_test.go
core/stores/cache/cachestat_test.go
package cache import ( "testing" "github.com/zeromicro/go-zero/core/timex" ) func TestCacheStat_statLoop(t *testing.T) { t.Run("stat loop total 0", func(t *testing.T) { var stat Stat ticker := timex.NewFakeTicker() go stat.statLoop(ticker) ticker.Tick() ticker.Tick() ticker.Stop() }) t.Run("stat lo...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/util.go
core/stores/cache/util.go
package cache import "strings" const keySeparator = "," // TotalWeights returns the total weights of given nodes. func TotalWeights(c []NodeConf) int { var weights int for _, node := range c { if node.Weight < 0 { node.Weight = 0 } weights += node.Weight } return weights } func formatKeys(keys []stri...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cleaner_test.go
core/stores/cache/cleaner_test.go
package cache import ( "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/timex" ) func TestNextDelay(t *testing.T) { tests := []struct { name string input time.Duration outpu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cacheopt.go
core/stores/cache/cacheopt.go
package cache import "time" const ( defaultExpiry = time.Hour * 24 * 7 defaultNotFoundExpiry = time.Minute ) type ( // Options is used to store the cache options. Options struct { Expiry time.Duration NotFoundExpiry time.Duration } // Option defines the method to customize an Options. Opt...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cachenode_test.go
core/stores/cache/cachenode_test.go
package cache import ( "errors" "fmt" "math/rand" "runtime" "strconv" "sync" "testing" "time" "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/mathx" "github....
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cachenode.go
core/stores/cache/cachenode.go
package cache import ( "context" "errors" "fmt" "math" "math/rand" "sync" "time" "github.com/zeromicro/go-zero/core/jsonx" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/mathx" "github.com/zeromicro/go-zero/core/stat" "github.com/zeromicro/go-zero/core/stores/redis" "github.c...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/stores/cache/cachestat.go
core/stores/cache/cachestat.go
package cache import ( "sync/atomic" "time" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/timex" ) const statInterval = time.Minute // A Stat is used to stat the cache. type Stat struct { name string // export the fields to let the unit tests working, // reside in internal packa...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false