github.com/blend/go-sdk@v1.20220411.3/expvar/string.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 "encoding/json" 12 "sync/atomic" 13 ) 14 15 // Assert that `String` implements `Var`. 16 var ( 17 _ Var = (*String)(nil) 18 ) 19 20 // String is a string variable, and satisfies the Var interface. 21 type String struct { 22 s atomic.Value // string 23 } 24 25 // Value returns the underlying value. 26 func (v *String) Value() string { 27 p, _ := v.s.Load().(string) 28 return p 29 } 30 31 // String implements the Var interface. To get the unquoted string 32 // use Value. 33 func (v *String) String() string { 34 s := v.Value() 35 b, _ := json.Marshal(s) 36 return string(b) 37 } 38 39 // Set sets the value 40 func (v *String) Set(value string) { 41 v.s.Store(value) 42 }