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/stat/internal/cgroup_linux.go
core/stat/internal/cgroup_linux.go
package internal import ( "bufio" "errors" "fmt" "math" "os" "path" "strconv" "strings" "sync" "time" "github.com/zeromicro/go-zero/core/iox" "github.com/zeromicro/go-zero/core/lang" "golang.org/x/sys/unix" ) const ( cgroupDir = "/sys/fs/cgroup" cpuMaxFile = cgroupDir + "/cpu.max" cpuStatFile = cg...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/configurator.go
core/configcenter/configurator.go
package configurator import ( "errors" "fmt" "reflect" "strings" "sync" "sync/atomic" "github.com/zeromicro/go-zero/core/configcenter/subscriber" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/mapping" "github.com/zeromicro/go-zero/core/threading" ) var ( errEmptyConfig ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/configurator_test.go
core/configcenter/configurator_test.go
package configurator import ( "errors" "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestNewConfigCenter(t *testing.T) { _, err := NewConfigCenter[any](Config{ Log: true, }, &mockSubscriber{}) assert.Error(t, err) _, err = NewConfigCenter[any](Config{ Type: "json", Log: true, ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/unmarshaler_test.go
core/configcenter/unmarshaler_test.go
package configurator import ( "testing" "github.com/stretchr/testify/assert" ) func TestRegisterUnmarshaler(t *testing.T) { RegisterUnmarshaler("test", func(data []byte, v interface{}) error { return nil }) _, ok := Unmarshaler("test") assert.True(t, ok) _, ok = Unmarshaler("test2") assert.False(t, ok) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/unmarshaler.go
core/configcenter/unmarshaler.go
package configurator import ( "sync" "github.com/zeromicro/go-zero/core/conf" ) var registry = &unmarshalerRegistry{ unmarshalers: map[string]LoaderFn{ "json": conf.LoadFromJsonBytes, "toml": conf.LoadFromTomlBytes, "yaml": conf.LoadFromYamlBytes, }, } type ( // LoaderFn is the function type for loading ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/subscriber/etcd.go
core/configcenter/subscriber/etcd.go
package subscriber import ( "sync" "sync/atomic" "github.com/zeromicro/go-zero/core/discov" "github.com/zeromicro/go-zero/core/logx" ) type ( // etcdSubscriber is a subscriber that subscribes to etcd. etcdSubscriber struct { *discov.Subscriber } // EtcdConf is the configuration for etcd. EtcdConf = disco...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/subscriber/subscriber.go
core/configcenter/subscriber/subscriber.go
package subscriber // Subscriber is the interface for configcenter subscribers. type Subscriber interface { // AddListener adds a listener to the subscriber. AddListener(listener func()) error // Value returns the value of the subscriber. Value() (string, error) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/configcenter/subscriber/etcd_test.go
core/configcenter/subscriber/etcd_test.go
package subscriber import ( "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/discov" ) const ( actionAdd = iota actionDel ) func TestConfigCenterContainer(t *testing.T) { type action struct { act int key string val string } tests := []struct { name string do ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/mr/mapreduce_fuzz_test.go
core/mr/mapreduce_fuzz_test.go
package mr import ( "fmt" "math/rand" "runtime" "strings" "testing" "time" "github.com/stretchr/testify/assert" "go.uber.org/goleak" ) func FuzzMapReduce(f *testing.F) { rand.NewSource(time.Now().UnixNano()) f.Add(int64(10), runtime.NumCPU()) f.Fuzz(func(t *testing.T, n int64, workers int) { n = n%5000...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/mr/mapreduce_fuzzcase_test.go
core/mr/mapreduce_fuzzcase_test.go
//go:build fuzz package mr import ( "fmt" "math/rand" "runtime" "strconv" "strings" "sync" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/threading" "gopkg.in/cheggaaa/pb.v1" ) // If Fuzz stuck, we don't know why, because it only returns hung or unexpected, // so...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/mr/mapreduce.go
core/mr/mapreduce.go
package mr import ( "context" "errors" "fmt" "runtime/debug" "strings" "sync" "sync/atomic" "github.com/zeromicro/go-zero/core/errorx" ) const ( defaultWorkers = 16 minWorkers = 1 ) var ( // ErrCancelWithNil is an error that mapreduce was cancelled with nil. ErrCancelWithNil = errors.New("mapreduce ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/mr/mapreduce_test.go
core/mr/mapreduce_test.go
package mr import ( "context" "errors" "fmt" "runtime" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "go.uber.org/goleak" ) var errDummy = errors.New("dummy") func TestFinish(t *testing.T) { defer goleak.VerifyNone(t) var total uint32 err := Finish(func() error { atomic.AddUint...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/contextx/valueonlycontext.go
core/contextx/valueonlycontext.go
package contextx import ( "context" "time" ) type valueOnlyContext struct { context.Context } func (valueOnlyContext) Deadline() (deadline time.Time, ok bool) { return } func (valueOnlyContext) Done() <-chan struct{} { return nil } func (valueOnlyContext) Err() error { return nil } // ValueOnlyFrom takes al...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/contextx/unmarshaler_test.go
core/contextx/unmarshaler_test.go
package contextx import ( "context" "testing" "github.com/stretchr/testify/assert" ) func TestUnmarshalContext(t *testing.T) { type Person struct { Name string `ctx:"name"` Age int `ctx:"age"` } ctx := context.Background() ctx = context.WithValue(ctx, "name", "kevin") ctx = context.WithValue(ctx, "a...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/contextx/unmarshaler.go
core/contextx/unmarshaler.go
package contextx import ( "context" "github.com/zeromicro/go-zero/core/mapping" ) const contextTagKey = "ctx" var unmarshaler = mapping.NewUnmarshaler(contextTagKey) type contextValuer struct { context.Context } func (cv contextValuer) Value(key string) (any, bool) { v := cv.Context.Value(key) return v, v !=...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/contextx/valueonlycontext_test.go
core/contextx/valueonlycontext_test.go
package contextx import ( "context" "testing" "time" "github.com/stretchr/testify/assert" ) func TestContextCancel(t *testing.T) { type key string var nameKey key = "name" c := context.WithValue(context.Background(), nameKey, "value") c1, cancel := context.WithCancel(c) o := ValueOnlyFrom(c1) c2, cancel2 :...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/search/tree.go
core/search/tree.go
package search import ( "errors" "fmt" ) const ( colon = ':' slash = '/' ) var ( // errDupItem means adding duplicated item. errDupItem = errors.New("duplicated item") // errDupSlash means item is started with more than one slash. errDupSlash = errors.New("duplicated slash") // errEmptyItem means adding emp...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/search/tree_debug.go
core/search/tree_debug.go
//go:build debug package search import "fmt" func (t *Tree) Print() { if t.root.item == nil { fmt.Println("/") } else { fmt.Printf("/:%#v\n", t.root.item) } printNode(t.root, 1) } func printNode(n *node, depth int) { indent := make([]byte, depth) for i := 0; i < len(indent); i++ { indent[i] = '\t' } ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/search/tree_test.go
core/search/tree_test.go
package search import ( "math/rand" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/stringx" ) type mockedRoute struct { route string value any } func TestSearch(t *testing.T) { routes := []mockedRoute{ {"/", 1}, {"/api", 2}, {"/img", 3}, {"/:layer1", 4}, ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/color/color_test.go
core/color/color_test.go
package color import ( "testing" "github.com/stretchr/testify/assert" ) func TestWithColor(t *testing.T) { output := WithColor("Hello", BgRed) assert.Equal(t, "Hello", output) } func TestWithColorPadding(t *testing.T) { output := WithColorPadding("Hello", BgRed) assert.Equal(t, " Hello ", output) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/color/color.go
core/color/color.go
package color import "github.com/fatih/color" const ( // NoColor is no color for both foreground and background. NoColor Color = iota // FgBlack is the foreground color black. FgBlack // FgRed is the foreground color red. FgRed // FgGreen is the foreground color green. FgGreen // FgYellow is the foreground c...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/profilecenter_test.go
core/prof/profilecenter_test.go
package prof import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestReport(t *testing.T) { assert.NotContains(t, generateReport(), "foo") report("foo", time.Second) assert.Contains(t, generateReport(), "foo") report("foo", time.Second) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/runtime_test.go
core/prof/runtime_test.go
package prof import ( "strings" "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestDisplayStats(t *testing.T) { writer := &threadSafeBuffer{ buf: strings.Builder{}, } displayStatsWithWriter(writer, time.Millisecond*10) time.Sleep(time.Millisecond * 50) assert.Contains(t, writer.Strin...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/profiler.go
core/prof/profiler.go
package prof import "github.com/zeromicro/go-zero/core/utils" type ( // A ProfilePoint is a profile time point. ProfilePoint struct { *utils.ElapsedTimer } // A Profiler interface represents a profiler that used to report profile points. Profiler interface { Start() ProfilePoint Report(name string, point ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/profiler_test.go
core/prof/profiler_test.go
package prof import ( "testing" "github.com/zeromicro/go-zero/core/utils" ) func TestProfiler(t *testing.T) { EnableProfiling() Start() Report("foo", ProfilePoint{ ElapsedTimer: utils.NewElapsedTimer(), }) } func TestNullProfiler(t *testing.T) { p := newNullProfiler() p.Start() p.Report("foo", ProfilePoi...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/runtime.go
core/prof/runtime.go
package prof import ( "fmt" "io" "os" "runtime" "runtime/debug" "runtime/metrics" "time" ) const ( defaultInterval = time.Second * 5 mega = 1024 * 1024 ) // DisplayStats prints the goroutine, memory, GC stats with given interval, default to 5 seconds. func DisplayStats(interval ...time.Duration) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prof/profilecenter.go
core/prof/profilecenter.go
package prof import ( "fmt" "strings" "sync" "sync/atomic" "time" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/threading" ) type ( profileSlot struct { lifecount int64 lastcount int64 lifecycle int64 lastcycle int64 } profileCenter struct { lock sync.RWMutex slo...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prometheus/agent.go
core/prometheus/agent.go
package prometheus import ( "fmt" "net/http" "sync" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/threading" ) var ( once sync.Once enabled syncx.AtomicBool ) // Enabled retu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/prometheus/config.go
core/prometheus/config.go
package prometheus // A Config is a prometheus config. type Config struct { Host string `json:",optional"` Port int `json:",default=9101"` Path string `json:",default=/metrics"` }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/validate.go
core/conf/validate.go
package conf import "github.com/zeromicro/go-zero/core/validation" // validate validates the value if it implements the Validator interface. func validate(v any) error { if val, ok := v.(validation.Validator); ok { return val.Validate() } return nil }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/config.go
core/conf/config.go
package conf import ( "fmt" "log" "os" "path" "reflect" "strings" "github.com/zeromicro/go-zero/core/jsonx" "github.com/zeromicro/go-zero/core/mapping" "github.com/zeromicro/go-zero/internal/encoding" ) const ( jsonTagKey = "json" jsonTagSep = ',' ) var ( fillDefaultUnmarshaler = mapping.NewUnmarshaler(...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/properties_test.go
core/conf/properties_test.go
package conf import ( "os" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" ) func TestProperties(t *testing.T) { text := `app.name = test app.program=app # this is comment app.threads = 5` tmpfile, err := fs.TempFilenameWithText(text) assert.Nil(t, err) def...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/config_test.go
core/conf/config_test.go
package conf import ( "errors" "os" "reflect" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/fs" "github.com/zeromicro/go-zero/core/hash" ) var dupErr conflictKeyError func TestLoadConfig_notExists(t *testing.T) { assert.NotNil(t, Load("not_a_file", nil)) } func TestLoadC...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/properties.go
core/conf/properties.go
package conf import ( "fmt" "os" "strconv" "strings" "sync" "github.com/zeromicro/go-zero/core/iox" ) // PropertyError represents a configuration error message. type PropertyError struct { message string } // Properties interface provides the means to access configuration. type Properties interface { GetStr...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/options.go
core/conf/options.go
package conf type ( // Option defines the method to customize the config options. Option func(opt *options) options struct { env bool } ) // UseEnv customizes the config to use environment variables. func UseEnv() Option { return func(opt *options) { opt.env = true } }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/conf/validate_test.go
core/conf/validate_test.go
package conf import ( "errors" "testing" "github.com/stretchr/testify/assert" ) type mockType int func (m mockType) Validate() error { if m < 10 { return errors.New("invalid value") } return nil } type anotherMockType int func Test_validate(t *testing.T) { tests := []struct { name string v ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/sheddingstat.go
core/load/sheddingstat.go
package load import ( "sync/atomic" "time" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stat" ) type ( // A SheddingStat is used to store the statistics for load shedding. SheddingStat struct { name string total int64 pass int64 drop int64 } snapshot struct { Tota...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/adaptiveshedder_test.go
core/load/adaptiveshedder_test.go
package load import ( "math/rand" "sync" "sync/atomic" "testing" "time" "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.com/zeromicro/go-zero/core/stat" "github.com/zeromicro/go-ze...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/sheddergroup.go
core/load/sheddergroup.go
package load import ( "io" "github.com/zeromicro/go-zero/core/syncx" ) // A ShedderGroup is a manager to manage key-based shedders. type ShedderGroup struct { options []ShedderOption manager *syncx.ResourceManager } // NewShedderGroup returns a ShedderGroup. func NewShedderGroup(opts ...ShedderOption) *ShedderG...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/sheddingstat_test.go
core/load/sheddingstat_test.go
package load import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestSheddingStat(t *testing.T) { st := NewSheddingStat("any") for i := 0; i < 3; i++ { st.IncrementTotal() } for i := 0; i < 5; i++ { st.IncrementPass() } for i := 0; i < 7; i++ { st.IncrementDrop() } result := st.res...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/nopshedder.go
core/load/nopshedder.go
package load type nopShedder struct{} func newNopShedder() Shedder { return nopShedder{} } func (s nopShedder) Allow() (Promise, error) { return nopPromise{}, nil } type nopPromise struct{} func (p nopPromise) Pass() { } func (p nopPromise) Fail() { }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/sheddergroup_test.go
core/load/sheddergroup_test.go
package load import ( "testing" "github.com/stretchr/testify/assert" ) func TestGroup(t *testing.T) { group := NewShedderGroup() t.Run("get", func(t *testing.T) { limiter := group.GetShedder("test") assert.NotNil(t, limiter) }) } func TestShedderClose(t *testing.T) { var nop nopCloser assert.Nil(t, nop.C...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/nopshedder_test.go
core/load/nopshedder_test.go
package load import ( "testing" "github.com/stretchr/testify/assert" ) func TestNopShedder(t *testing.T) { Disable() shedder := NewAdaptiveShedder() for i := 0; i < 1000; i++ { p, err := shedder.Allow() assert.Nil(t, err) p.Fail() } p, err := shedder.Allow() assert.Nil(t, err) p.Pass() }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/load/adaptiveshedder.go
core/load/adaptiveshedder.go
package load import ( "errors" "fmt" "math" "sync/atomic" "time" "github.com/zeromicro/go-zero/core/collection" "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/syncx" "github.com/zeromicro/go-zero...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/stablerunner_test.go
core/threading/stablerunner_test.go
package threading import ( "math/rand" "sort" "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestStableRunner(t *testing.T) { size := bufSize * 2 rand.NewSource(time.Now().UnixNano()) runner := NewStableRunner(func(v int) float64 { if v == 0 { time.Sleep(time.Millisecond * 100) }...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/routinegroup_test.go
core/threading/routinegroup_test.go
package threading import ( "sync" "sync/atomic" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/logx/logtest" ) func TestRoutineGroupRun(t *testing.T) { var count int32 group := NewRoutineGroup() for i := 0; i < 3; i++ { group.Run(func() { atomic.AddInt32(&count, 1) }...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/workergroup.go
core/threading/workergroup.go
package threading // A WorkerGroup is used to run given number of workers to process jobs. type WorkerGroup struct { job func() workers int } // NewWorkerGroup returns a WorkerGroup with given job and workers. func NewWorkerGroup(job func(), workers int) WorkerGroup { return WorkerGroup{ job: job, work...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/routinegroup.go
core/threading/routinegroup.go
package threading import "sync" // A RoutineGroup is used to group goroutines together and all wait all goroutines to be done. type RoutineGroup struct { waitGroup sync.WaitGroup } // NewRoutineGroup returns a RoutineGroup. func NewRoutineGroup() *RoutineGroup { return new(RoutineGroup) } // Run runs the given fn...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/taskrunner.go
core/threading/taskrunner.go
package threading import ( "errors" "sync" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/rescue" ) // ErrTaskRunnerBusy is the error that indicates the runner is busy. var ErrTaskRunnerBusy = errors.New("task runner is busy") // A TaskRunner is used to control the concurrency of go...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/taskrunner_test.go
core/threading/taskrunner_test.go
package threading import ( "runtime" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" ) func TestTaskRunner_Schedule(t *testing.T) { times := 100 pool := NewTaskRunner(runtime.NumCPU()) var counter int32 for i := 0; i < times; i++ { pool.Schedule(func() { atomic.AddInt32(&counter, 1...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/workergroup_test.go
core/threading/workergroup_test.go
package threading import ( "fmt" "runtime" "sync" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/lang" ) func TestWorkerGroup(t *testing.T) { m := make(map[string]lang.PlaceholderType) var lock sync.Mutex var wg sync.WaitGroup wg.Add(runtime.NumCPU()) group := NewWorkerG...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/routines_test.go
core/threading/routines_test.go
package threading import ( "bytes" "context" "testing" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx/logtest" ) func TestRoutineId(t *testing.T) { assert.True(t, RoutineId() > 0) } func TestRunSa...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/stablerunner.go
core/threading/stablerunner.go
package threading import ( "errors" "runtime" "sync" "sync/atomic" "time" ) const factor = 10 var ( ErrRunnerClosed = errors.New("runner closed") bufSize = runtime.NumCPU() * factor ) // StableRunner is a runner that guarantees messages are taken out with the pushed order. // This runner is typically useful...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/threading/routines.go
core/threading/routines.go
package threading import ( "bytes" "context" "runtime" "strconv" "github.com/zeromicro/go-zero/core/rescue" ) // GoSafe runs the given fn using another goroutine, recovers if fn panics. func GoSafe(fn func()) { go RunSafe(fn) } // GoSafeCtx runs the given fn using another goroutine, recovers if fn panics with...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/jsonx/json.go
core/jsonx/json.go
package jsonx import ( "bytes" "encoding/json" "fmt" "io" "strings" ) // Marshal marshals v into json bytes, without escaping HTML and removes the trailing newline. func Marshal(v any) ([]byte, error) { // why not use json.Marshal? https://github.com/golang/go/issues/28453 // it changes the behavior of json.M...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/jsonx/json_test.go
core/jsonx/json_test.go
package jsonx import ( "fmt" "strings" "testing" "github.com/stretchr/testify/assert" ) func TestMarshal(t *testing.T) { var v = struct { Name string `json:"name"` Age int `json:"age"` }{ Name: "John", Age: 30, } bs, err := Marshal(v) assert.Nil(t, err) assert.Equal(t, `{"name":"John","age":30...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fs/files_test.go
core/fs/files_test.go
package fs import ( "os" "testing" "github.com/stretchr/testify/assert" ) func TestCloseOnExec(t *testing.T) { file := os.NewFile(0, os.DevNull) assert.NotPanics(t, func() { CloseOnExec(file) }) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fs/temps_test.go
core/fs/temps_test.go
package fs import ( "io" "os" "testing" "github.com/stretchr/testify/assert" ) func TestTempFileWithText(t *testing.T) { f, err := TempFileWithText("test") if err != nil { t.Error(err) } if f == nil { t.Error("TempFileWithText returned nil") } if f.Name() == "" { t.Error("TempFileWithText returned em...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fs/files.go
core/fs/files.go
//go:build linux || darwin || freebsd package fs import ( "os" "syscall" ) // CloseOnExec makes sure closing the file on process forking. func CloseOnExec(file *os.File) { if file != nil { syscall.CloseOnExec(int(file.Fd())) } }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fs/temps.go
core/fs/temps.go
package fs import ( "os" "github.com/zeromicro/go-zero/core/hash" ) // TempFileWithText creates the temporary file with the given content, // and returns the opened *os.File instance. // The file is kept as open, the caller should close the file handle, // and remove the file by name. func TempFileWithText(text st...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fs/files+polyfill.go
core/fs/files+polyfill.go
//go:build windows package fs import "os" func CloseOnExec(*os.File) { }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/naming/namer.go
core/naming/namer.go
package naming // Namer interface wraps the method Name. type Namer interface { Name() string }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/stream.go
core/fx/stream.go
package fx import ( "sort" "sync" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/threading" ) const ( defaultWorkers = 16 minWorkers = 1 ) type ( rxOptions struct { unlimitedWorkers bool workers int } // FilterFu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/timeout_test.go
core/fx/timeout_test.go
package fx import ( "context" "testing" "time" "github.com/stretchr/testify/assert" ) func TestWithPanic(t *testing.T) { assert.Panics(t, func() { _ = DoWithTimeout(func() error { panic("hello") }, time.Millisecond*50) }) } func TestWithTimeout(t *testing.T) { assert.Equal(t, ErrTimeout, DoWithTimeout...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/retry_test.go
core/fx/retry_test.go
package fx import ( "context" "errors" "testing" "time" "github.com/stretchr/testify/assert" ) func TestRetry(t *testing.T) { assert.NotNil(t, DoWithRetry(func() error { return errors.New("any") })) times1 := 0 assert.Nil(t, DoWithRetry(func() error { times1++ if times1 == defaultRetryTimes { retu...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/retry.go
core/fx/retry.go
package fx import ( "context" "errors" "time" "github.com/zeromicro/go-zero/core/errorx" ) const defaultRetryTimes = 3 type ( // RetryOption defines the method to customize DoWithRetry. RetryOption func(*retryOptions) retryOptions struct { times int interval time.Duration timeout time....
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/parallel_test.go
core/fx/parallel_test.go
package fx import ( "errors" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" ) func TestParallel(t *testing.T) { var count int32 Parallel(func() { time.Sleep(time.Millisecond * 100) atomic.AddInt32(&count, 1) }, func() { time.Sleep(time.Millisecond * 100) atomic.AddInt32(&count, 2...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/parallel.go
core/fx/parallel.go
package fx import ( "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/threading" ) // Parallel runs fns parallelly and waits for done. func Parallel(fns ...func()) { group := threading.NewRoutineGroup() for _, fn := range fns { group.RunSafe(fn) } group.Wait() } func ParallelErr(f...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/timeout.go
core/fx/timeout.go
package fx import ( "context" "fmt" "runtime/debug" "strings" "time" ) var ( // ErrCanceled is the error returned when the context is canceled. ErrCanceled = context.Canceled // ErrTimeout is the error returned when the context's deadline passes. ErrTimeout = context.DeadlineExceeded ) // DoOption defines t...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/fx/stream_test.go
core/fx/stream_test.go
package fx import ( "math/rand" "reflect" "runtime" "sort" "sync" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/logx/logtest" "github.com/zeromicro/go-zero/core/stringx" "go.uber.org/goleak" ) func TestBuffer(t *testing.T) { runCheckedTest(t, func...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/singleflight_test.go
core/syncx/singleflight_test.go
package syncx import ( "errors" "fmt" "sync" "sync/atomic" "testing" "time" ) func TestExclusiveCallDo(t *testing.T) { g := NewSingleFlight() v, err := g.Do("key", func() (any, error) { return "bar", nil }) if got, want := fmt.Sprintf("%v (%T)", v, v), "bar (string)"; got != want { t.Errorf("Do = %v; wa...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/resourcemanager.go
core/syncx/resourcemanager.go
package syncx import ( "io" "sync" "github.com/zeromicro/go-zero/core/errorx" ) // A ResourceManager is a manager that used to manage resources. type ResourceManager struct { resources map[string]io.Closer singleFlight SingleFlight lock sync.RWMutex } // NewResourceManager returns a ResourceManager...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/refresource_test.go
core/syncx/refresource_test.go
package syncx import ( "testing" "github.com/stretchr/testify/assert" ) func TestRefCleaner(t *testing.T) { var count int clean := func() { count += 1 } cleaner := NewRefResource(clean) err := cleaner.Use() assert.Nil(t, err) err = cleaner.Use() assert.Nil(t, err) cleaner.Clean() cleaner.Clean() asse...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/donechan_test.go
core/syncx/donechan_test.go
package syncx import ( "sync" "testing" ) func TestDoneChanClose(t *testing.T) { doneChan := NewDoneChan() for i := 0; i < 5; i++ { doneChan.Close() } } func TestDoneChanDone(t *testing.T) { var waitGroup sync.WaitGroup doneChan := NewDoneChan() waitGroup.Add(1) go func() { <-doneChan.Done() waitGro...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/limit_test.go
core/syncx/limit_test.go
package syncx import ( "testing" "github.com/stretchr/testify/assert" ) func TestLimit(t *testing.T) { limit := NewLimit(2) limit.Borrow() assert.True(t, limit.TryBorrow()) assert.False(t, limit.TryBorrow()) assert.Nil(t, limit.Return()) assert.Nil(t, limit.Return()) assert.Equal(t, ErrLimitReturn, limit.Re...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/cond_test.go
core/syncx/cond_test.go
package syncx import ( "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestTimeoutCondWait(t *testing.T) { var wait sync.WaitGroup cond := NewCond() wait.Add(2) go func() { cond.Wait() wait.Done() }() time.Sleep(time.Duration(50) * time.Millisecond) go func() { cond.Signal() wa...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/onceguard.go
core/syncx/onceguard.go
package syncx import "sync/atomic" // An OnceGuard is used to make sure a resource can be taken once. type OnceGuard struct { done uint32 } // Taken checks if the resource is taken. func (og *OnceGuard) Taken() bool { return atomic.LoadUint32(&og.done) == 1 } // Take takes the resource, returns true on success, f...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/donechan.go
core/syncx/donechan.go
package syncx import ( "sync" "github.com/zeromicro/go-zero/core/lang" ) // A DoneChan is used as a channel that can be closed multiple times and wait for done. type DoneChan struct { done chan lang.PlaceholderType once sync.Once } // NewDoneChan returns a DoneChan. func NewDoneChan() *DoneChan { return &DoneC...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/timeoutlimit.go
core/syncx/timeoutlimit.go
package syncx import ( "errors" "time" ) // ErrTimeout is an error that indicates the borrow timeout. var ErrTimeout = errors.New("borrow timeout") // A TimeoutLimit is used to borrow with timeouts. type TimeoutLimit struct { limit Limit cond *Cond } // NewTimeoutLimit returns a TimeoutLimit. func NewTimeoutLi...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/managedresource_test.go
core/syncx/managedresource_test.go
package syncx import ( "sync/atomic" "testing" "github.com/stretchr/testify/assert" ) func TestManagedResource(t *testing.T) { var count int32 resource := NewManagedResource(func() any { return atomic.AddInt32(&count, 1) }, func(a, b any) bool { return a == b }) assert.Equal(t, resource.Take(), resource...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/pool_test.go
core/syncx/pool_test.go
package syncx import ( "sync" "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/lang" ) const limit = 10 func TestPoolGet(t *testing.T) { stack := NewPool(limit, create, destroy) ch := make(chan lang.PlaceholderType) for i := 0; i < limit; i++ { var f...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/atomicfloat64.go
core/syncx/atomicfloat64.go
package syncx import ( "math" "sync/atomic" ) // An AtomicFloat64 is an implementation of atomic float64. type AtomicFloat64 uint64 // NewAtomicFloat64 returns an AtomicFloat64. func NewAtomicFloat64() *AtomicFloat64 { return new(AtomicFloat64) } // ForAtomicFloat64 returns an AtomicFloat64 with given val. func ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/atomicbool_test.go
core/syncx/atomicbool_test.go
package syncx import ( "testing" "github.com/stretchr/testify/assert" ) func TestAtomicBool(t *testing.T) { val := ForAtomicBool(true) assert.True(t, val.True()) val.Set(false) assert.False(t, val.True()) val.Set(true) assert.True(t, val.True()) val.Set(false) assert.False(t, val.True()) ok := val.Compare...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/spinlock.go
core/syncx/spinlock.go
package syncx import ( "runtime" "sync/atomic" ) // A SpinLock is used as a lock a fast execution. type SpinLock struct { lock uint32 } // Lock locks the SpinLock. func (sl *SpinLock) Lock() { for !sl.TryLock() { runtime.Gosched() } } // TryLock tries to lock the SpinLock. func (sl *SpinLock) TryLock() bool ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/atomicduration.go
core/syncx/atomicduration.go
package syncx import ( "sync/atomic" "time" ) // An AtomicDuration is an implementation of atomic duration. type AtomicDuration int64 // NewAtomicDuration returns an AtomicDuration. func NewAtomicDuration() *AtomicDuration { return new(AtomicDuration) } // ForAtomicDuration returns an AtomicDuration with given v...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/onceguard_test.go
core/syncx/onceguard_test.go
package syncx import ( "testing" "github.com/stretchr/testify/assert" ) func TestOnceGuard(t *testing.T) { var guard OnceGuard assert.False(t, guard.Taken()) assert.True(t, guard.Take()) assert.True(t, guard.Taken()) assert.False(t, guard.Take()) assert.True(t, guard.Taken()) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/singleflight.go
core/syncx/singleflight.go
package syncx import "sync" type ( // SingleFlight lets the concurrent calls with the same key to share the call result. // For example, A called F, before it's done, B called F. Then B would not execute F, // and shared the result returned by F which called by A. // The calls with the same key are dependent, con...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/lockedcalls_test.go
core/syncx/lockedcalls_test.go
package syncx import ( "errors" "fmt" "sync" "testing" "time" ) func TestLockedCallDo(t *testing.T) { g := NewLockedCalls() v, err := g.Do("key", func() (any, error) { return "bar", nil }) if got, want := fmt.Sprintf("%v (%T)", v, v), "bar (string)"; got != want { t.Errorf("Do = %v; want %v", got, want) ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/atomicfloat64_test.go
core/syncx/atomicfloat64_test.go
package syncx import ( "sync" "testing" "github.com/stretchr/testify/assert" ) func TestAtomicFloat64(t *testing.T) { f := ForAtomicFloat64(100) var wg sync.WaitGroup for i := 0; i < 5; i++ { wg.Add(1) go func() { for i := 0; i < 100; i++ { f.Add(1) } wg.Done() }() } wg.Wait() assert.Equa...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/limit.go
core/syncx/limit.go
package syncx import ( "errors" "github.com/zeromicro/go-zero/core/lang" ) // ErrLimitReturn indicates that the more than borrowed elements were returned. var ErrLimitReturn = errors.New("discarding limited token, resource pool is full, someone returned multiple times") // Limit controls the concurrent requests. ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/lockedcalls.go
core/syncx/lockedcalls.go
package syncx import "sync" type ( // LockedCalls makes sure the calls with the same key to be called sequentially. // For example, A called F, before it's done, B called F, then B's call would not blocked, // after A's call finished, B's call got executed. // The calls with the same key are independent, not shar...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/barrier_test.go
core/syncx/barrier_test.go
package syncx import ( "sync" "testing" "github.com/stretchr/testify/assert" ) func TestBarrier_Guard(t *testing.T) { const total = 10000 var barrier Barrier var count int var wg sync.WaitGroup wg.Add(total) for i := 0; i < total; i++ { go barrier.Guard(func() { count++ wg.Done() }) } wg.Wait() ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/once_test.go
core/syncx/once_test.go
package syncx import ( "testing" "github.com/stretchr/testify/assert" ) func TestOnce(t *testing.T) { var v int add := Once(func() { v++ }) for i := 0; i < 5; i++ { add() } assert.Equal(t, 1, v) } func BenchmarkOnce(b *testing.B) { var v int add := Once(func() { v++ }) b.ResetTimer() for i := ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/once.go
core/syncx/once.go
package syncx import "sync" // Once returns a func that guarantees fn can only called once. // Deprecated: use sync.OnceFunc instead. func Once(fn func()) func() { return sync.OnceFunc(fn) }
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/pool.go
core/syncx/pool.go
package syncx import ( "sync" "time" "github.com/zeromicro/go-zero/core/timex" ) type ( // PoolOption defines the method to customize a Pool. PoolOption func(*Pool) node struct { item any next *node lastUsed time.Duration } // A Pool is used to pool resources. // The difference between sync....
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/refresource.go
core/syncx/refresource.go
package syncx import ( "errors" "sync" ) // ErrUseOfCleaned is an error that indicates using a cleaned resource. var ErrUseOfCleaned = errors.New("using a cleaned resource") // A RefResource is used to reference counting a resource. type RefResource struct { lock sync.Mutex ref int32 cleaned bool clean ...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/atomicduration_test.go
core/syncx/atomicduration_test.go
package syncx import ( "testing" "time" "github.com/stretchr/testify/assert" ) func TestAtomicDuration(t *testing.T) { d := ForAtomicDuration(time.Duration(100)) assert.Equal(t, time.Duration(100), d.Load()) d.Set(time.Duration(200)) assert.Equal(t, time.Duration(200), d.Load()) assert.True(t, d.CompareAndSw...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/cond.go
core/syncx/cond.go
package syncx import ( "time" "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/timex" ) // A Cond is used to wait for conditions. type Cond struct { signal chan lang.PlaceholderType } // NewCond returns a Cond. func NewCond() *Cond { return &Cond{ signal: make(chan lang.Placeholder...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/immutableresource.go
core/syncx/immutableresource.go
package syncx import ( "sync" "time" "github.com/zeromicro/go-zero/core/timex" ) const defaultRefreshInterval = time.Second type ( // ImmutableResourceOption defines the method to customize an ImmutableResource. ImmutableResourceOption func(resource *ImmutableResource) // An ImmutableResource is used to mana...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false
zeromicro/go-zero
https://github.com/zeromicro/go-zero/blob/8e7e5695eb2095917864b5d6615dab4c90bde3ac/core/syncx/timeoutlimit_test.go
core/syncx/timeoutlimit_test.go
package syncx import ( "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestTimeoutLimit(t *testing.T) { tests := []struct { name string interval time.Duration }{ { name: "no wait", }, { name: "wait", interval: time.Millisecond * 100, }, } for _, test := range...
go
MIT
8e7e5695eb2095917864b5d6615dab4c90bde3ac
2026-01-07T08:36:18.042207Z
false