gitlab.com/infor-cloud/martian-cloud/tharsis/go-limiter@v0.0.0-20230411193226-3247984d5abc/memorystore/example_test.go (about) 1 package memorystore_test 2 3 import ( 4 "context" 5 "log" 6 "time" 7 8 "gitlab.com/infor-cloud/martian-cloud/tharsis/go-limiter/memorystore" 9 ) 10 11 func ExampleNew() { 12 ctx := context.Background() 13 14 store, err := memorystore.New(&memorystore.Config{ 15 Tokens: 15, 16 Interval: time.Minute, 17 }) 18 if err != nil { 19 log.Fatal(err) 20 } 21 defer store.Close(ctx) 22 23 limit, remaining, reset, ok, err := store.Take(ctx, "my-key") 24 if err != nil { 25 log.Fatal(err) 26 } 27 _, _, _, _ = limit, remaining, reset, ok 28 } 29 30 func ExampleNew_takeMany() { 31 ctx := context.Background() 32 33 store, err := memorystore.New(&memorystore.Config{ 34 Tokens: 50, 35 Interval: time.Second, 36 }) 37 if err != nil { 38 log.Fatal(err) 39 } 40 defer store.Close(ctx) 41 42 limit, remaining, reset, ok, err := store.TakeMany(ctx, "my-key", 15) 43 if err != nil { 44 log.Fatal(err) 45 } 46 _, _, _, _ = limit, remaining, reset, ok 47 }