github.com/blend/go-sdk@v1.20220411.3/expvar/int.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package expvar 9 10 import ( 11 "strconv" 12 "sync/atomic" 13 ) 14 15 // Assert that `Func` implements `Var`. 16 var ( 17 _ Var = (*Int)(nil) 18 ) 19 20 // Int is a 64-bit integer variable that satisfies the Var interface. 21 type Int struct { 22 i int64 23 } 24 25 // Value returns the current value. 26 func (v *Int) Value() int64 { 27 return atomic.LoadInt64(&v.i) 28 } 29 30 // String satisfies `Var`. 31 func (v *Int) String() string { 32 return strconv.FormatInt(atomic.LoadInt64(&v.i), 10) 33 } 34 35 // Add adds to the value. 36 func (v *Int) Add(delta int64) int64 { 37 return atomic.AddInt64(&v.i, delta) 38 } 39 40 // Set sets the value 41 func (v *Int) Set(value int64) { 42 atomic.StoreInt64(&v.i, value) 43 }