_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q173200
PublicKey
validation
func (ks *Keystore) PublicKey() (crypto.PublicKey, bool) { ks.rw.RLock() key, pub := ks.Key, ks.PubKey ks.rw.RUnlock() if pub != nil { return pub, true } // generate the public key if key != nil { ks.rw.Lock() defer ks.rw.Unlock() if x, ok := key.(interface { Public() crypto.PublicKey }); ok { ...
go
{ "resource": "" }
q173201
PrivateKey
validation
func (ks *Keystore) PrivateKey() (crypto.PrivateKey, bool) { ks.rw.RLock() defer ks.rw.RUnlock() return ks.Key, ks.Key != nil }
go
{ "resource": "" }
q173202
RegisterLocation
validation
func (t *Transport) RegisterLocation(loc string, path string) { t.mu.Lock() defer t.mu.Unlock() if t.loc == nil { t.loc = make(map[string]string) } if _, exists := t.loc[loc]; exists { panic("location " + loc + " already registered") } t.loc[loc] = path }
go
{ "resource": "" }
q173203
NewArena
validation
func NewArena(size uint32) *Arena { // Don't store data at position 0 in order to reserve offset=0 as a kind // of nil pointer. out := &Arena{ n: 1, buf: make([]byte, size), } return out }
go
{ "resource": "" }
q173204
NewSkiplist
validation
func NewSkiplist(arena *Arena) *Skiplist { // Allocate head and tail nodes. head, err := newNode(arena, maxHeight) if err != nil { panic("arenaSize is not large enough to hold the head node") } tail, err := newNode(arena, maxHeight) if err != nil { panic("arenaSize is not large enough to hold the tail node")...
go
{ "resource": "" }
q173205
Init
validation
func (it *Iterator) Init(list *Skiplist) { it.list = list it.arena = list.arena it.nd = nil it.value = 0 }
go
{ "resource": "" }
q173206
Value
validation
func (it *Iterator) Value() []byte { valOffset, valSize := decodeValue(it.value) return it.arena.GetBytes(valOffset, uint32(valSize)) }
go
{ "resource": "" }
q173207
Set
validation
func (it *Iterator) Set(val []byte, meta uint16) error { new, err := it.list.allocVal(val, meta) if err != nil { return err } return it.trySetValue(new) }
go
{ "resource": "" }
q173208
SetMeta
validation
func (it *Iterator) SetMeta(meta uint16) error { // Try to reuse the same value bytes. Do this only in the case where meta // is increasing, in order to avoid cases where the meta is changed, then // changed back to the original value, which would make it impossible to // detect updates had occurred in the interim....
go
{ "resource": "" }
q173209
Delete
validation
func (it *Iterator) Delete() error { if !atomic.CompareAndSwapUint64(&it.nd.value, it.value, deletedVal) { if it.setNode(it.nd, false) { return ErrRecordUpdated } return nil } // Deletion succeeded, so position iterator on next non-deleted node. next := it.list.getNext(it.nd, 0) it.setNode(next, false) ...
go
{ "resource": "" }
q173210
isSameArray
validation
func isSameArray(val1, val2 []byte) bool { if len(val1) == len(val2) && len(val1) > 0 { return &val1[0] == &val2[0] } return false }
go
{ "resource": "" }
q173211
New
validation
func New( ctx context.Context, host string, opts ClientOptions, debug bool) (Client, error) { if host == "" { return nil, errNewClient } host = strings.Replace(host, "/api", "", 1) c := &client{ http: &http.Client{}, host: host, } if opts.Timeout != 0 { c.http.Timeout = opts.Timeout } if opts.I...
go
{ "resource": "" }
q173212
WriteIndentedN
validation
func WriteIndentedN(w io.Writer, b []byte, n int) error { s := bufio.NewScanner(bytes.NewReader(b)) if !s.Scan() { return nil } l := s.Text() for { for x := 0; x < n; x++ { if _, err := fmt.Fprint(w, " "); err != nil { return err } } if _, err := fmt.Fprint(w, l); err != nil { return err } ...
go
{ "resource": "" }
q173213
WriteIndented
validation
func WriteIndented(w io.Writer, b []byte) error { return WriteIndentedN(w, b, 4) }
go
{ "resource": "" }
q173214
NewReporter
validation
func NewReporter(bufferSize, poolSize int, transport http.RoundTripper) Reporter { r := new(BasicReporter) if transport == nil { transport = &http.Transport{ // Allow for an idle connection per goroutine. MaxIdleConnsPerHost: poolSize, } } r.client = &http.Client{Transport: transport} r.reports = make(ch...
go
{ "resource": "" }
q173215
PostCount
validation
func PostCount(statKey, userKey string, count int) error { return DefaultReporter.PostCount(statKey, userKey, count) }
go
{ "resource": "" }
q173216
PostCountTime
validation
func PostCountTime(statKey, userKey string, count int, timestamp int64) error { return DefaultReporter.PostCountTime(statKey, userKey, count, timestamp) }
go
{ "resource": "" }
q173217
PostValue
validation
func PostValue(statKey, userKey string, value float64) error { return DefaultReporter.PostValue(statKey, userKey, value) }
go
{ "resource": "" }
q173218
PostValueTime
validation
func PostValueTime(statKey, userKey string, value float64, timestamp int64) error { return DefaultReporter.PostValueTime(statKey, userKey, value, timestamp) }
go
{ "resource": "" }
q173219
PostEZCount
validation
func PostEZCount(statName, ezkey string, count int) error { return DefaultReporter.PostEZCount(statName, ezkey, count) }
go
{ "resource": "" }
q173220
PostEZCountTime
validation
func PostEZCountTime(statName, ezkey string, count int, timestamp int64) error { return DefaultReporter.PostEZCountTime(statName, ezkey, count, timestamp) }
go
{ "resource": "" }
q173221
PostEZValue
validation
func PostEZValue(statName, ezkey string, value float64) error { return DefaultReporter.PostEZValue(statName, ezkey, value) }
go
{ "resource": "" }
q173222
PostEZValueTime
validation
func PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error { return DefaultReporter.PostEZValueTime(statName, ezkey, value, timestamp) }
go
{ "resource": "" }
q173223
PostCount
validation
func (r *BasicReporter) PostCount(statKey, userKey string, count int) error { r.add(newClassicStatCount(statKey, userKey, count)) return nil }
go
{ "resource": "" }
q173224
PostCountTime
validation
func (r *BasicReporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error { x := newClassicStatCount(statKey, userKey, count) x.Timestamp = timestamp r.add(x) return nil }
go
{ "resource": "" }
q173225
PostCountOne
validation
func (r *BasicReporter) PostCountOne(statKey, userKey string) error { return r.PostCount(statKey, userKey, 1) }
go
{ "resource": "" }
q173226
PostValue
validation
func (r *BasicReporter) PostValue(statKey, userKey string, value float64) error { r.add(newClassicStatValue(statKey, userKey, value)) return nil }
go
{ "resource": "" }
q173227
PostValueTime
validation
func (r *BasicReporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error { x := newClassicStatValue(statKey, userKey, value) x.Timestamp = timestamp r.add(x) return nil }
go
{ "resource": "" }
q173228
PostEZCountOne
validation
func (r *BasicReporter) PostEZCountOne(statName, ezkey string) error { return r.PostEZCount(statName, ezkey, 1) }
go
{ "resource": "" }
q173229
PostEZCount
validation
func (r *BasicReporter) PostEZCount(statName, ezkey string, count int) error { r.add(newEZStatCount(statName, ezkey, count)) return nil }
go
{ "resource": "" }
q173230
PostEZCountTime
validation
func (r *BasicReporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error { x := newEZStatCount(statName, ezkey, count) x.Timestamp = timestamp r.add(x) return nil }
go
{ "resource": "" }
q173231
PostEZValue
validation
func (r *BasicReporter) PostEZValue(statName, ezkey string, value float64) error { r.add(newEZStatValue(statName, ezkey, value)) return nil }
go
{ "resource": "" }
q173232
PostEZValueTime
validation
func (r *BasicReporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error { x := newEZStatValue(statName, ezkey, value) x.Timestamp = timestamp r.add(x) return nil }
go
{ "resource": "" }
q173233
NewBatchReporter
validation
func NewBatchReporter(reporter Reporter, interval time.Duration) Reporter { br := &BatchReporter{ r: reporter, batchInterval: interval, caches: make(map[string]*statCache), shutdownBatchCh: make(chan struct{}), } go br.batchLoop() return br }
go
{ "resource": "" }
q173234
cleanHost
validation
func (host rawHost) cleanHost() Host { output := Host{ nil, host.Status.State, host.Address.Address, host.Address.AddressType, []Hostname{}, []Port{}, } for _, hostname := range host.Hostnames.Hostnames { output.Hostnames = append(output.Hostnames, Hostname{hostname.Name, hostname.Type}) } for _,...
go
{ "resource": "" }
q173235
GetHost
validation
func (s Scan) GetHost(hostTarget string) (target Host, exists bool) { target, ok := s.Hosts[hostTarget] if ok { return target, true } for _, host := range s.Hosts { for _, hostname := range host.Hostnames { if hostname.Name == hostTarget { return host, true } } } return Host{}, false }
go
{ "resource": "" }
q173236
Rescan
validation
func (h Host) Rescan() (scan Scan) { return Init(). AddPorts(h.parentScan.configPorts...). AddTCPPorts(h.parentScan.configTCPPorts...). AddUDPPorts(h.parentScan.configUDPPorts...). AddHosts(h.Address). AddFlags(h.parentScan.configOpts...) }
go
{ "resource": "" }
q173237
Diff
validation
func (h Host) Diff(altHost Host) (added []Port, removed []Port) { targetPorts := h.Ports altPorts := altHost.Ports addedWithClosed := array.Except(altPorts, targetPorts).([]Port) for _, add := range addedWithClosed { if add.State != "closed" { added = append(added, add) } } removedWithClosed := array.Exce...
go
{ "resource": "" }
q173238
ToString
validation
func (h Host) ToString() (out string) { out += fmt.Sprintf("%s is %s\n", h.Address, h.State) if len(h.Hostnames) != 0 { out += "Hostnames:\n" for _, hostname := range h.Hostnames { out += fmt.Sprintf(" %s/%s\n", hostname.Name, hostname.Type) } } if len(h.Ports) != 0 { out += "Ports:\n" for _, port := ...
go
{ "resource": "" }
q173239
Init
validation
func Init() Scan { scan := Scan{} scan.Hosts = make(map[string]Host, 0) return scan }
go
{ "resource": "" }
q173240
AddHosts
validation
func (s Scan) AddHosts(hosts ...string) Scan { s.configHosts = append(s.configHosts, hosts...) return s }
go
{ "resource": "" }
q173241
SetHosts
validation
func (s Scan) SetHosts(hosts ...string) Scan { s.configHosts = hosts return s }
go
{ "resource": "" }
q173242
AddPorts
validation
func (s Scan) AddPorts(ports ...uint16) Scan { s.configPorts = append(s.configPorts, ports...) return s }
go
{ "resource": "" }
q173243
SetPorts
validation
func (s Scan) SetPorts(ports ...uint16) Scan { s.configPorts = ports return s }
go
{ "resource": "" }
q173244
SetTCPPorts
validation
func (s Scan) SetTCPPorts(ports ...uint16) Scan { s.configTCPPorts = ports return s }
go
{ "resource": "" }
q173245
SetUDPPorts
validation
func (s Scan) SetUDPPorts(ports ...uint16) Scan { s.configUDPPorts = ports return s }
go
{ "resource": "" }
q173246
AddFlags
validation
func (s Scan) AddFlags(flags ...string) Scan { for _, flag := range flags { if strings.Contains(flag, " ") { s.configErr = errors.New("Flags must not have spaces in them") return s } for _, df := range DisallowedFlags { if flag == df { s.configErr = &DisallowedFlagError{df} return s } } } ...
go
{ "resource": "" }
q173247
IntenseAllTCPPorts
validation
func (s Scan) IntenseAllTCPPorts() Scan { return s.Intense(). SetPorts(). SetUDPPorts(). SetTCPPorts(). AddPortRange(1, 65535) }
go
{ "resource": "" }
q173248
ToString
validation
func (s Scan) ToString() (out string) { for _, host := range s.Hosts { out += fmt.Sprintf("%s\n", host.ToString()) } return }
go
{ "resource": "" }
q173249
CreateNmapArgs
validation
func (s Scan) CreateNmapArgs() ([]string, error) { // Parse arguments args := []string{"-oX", "-"} const seperator string = "," // Set up ports portList := "" portList += strings.Join(uint16ListToStringList(s.configPorts), seperator) if len(s.configUDPPorts) != 0 { if portList != "" { portList += "," } ...
go
{ "resource": "" }
q173250
uint16ListToStringList
validation
func uint16ListToStringList(source []uint16) (o []string) { for _, s := range source { o = append(o, strconv.FormatUint(uint64(s), 10)) } return }
go
{ "resource": "" }
q173251
ToString
validation
func (p Port) ToString() (out string) { out += fmt.Sprintf("Port %d/%s is %s\n", p.ID, p.Protocol, p.State) for _, script := range p.Scripts { output := "" for _, line := range strings.Split(script.Output, "\n") { output += fmt.Sprintf(" %s\n", line) } out += fmt.Sprintf(" Script: %s\n%s\n", script.N...
go
{ "resource": "" }
q173252
Counter
validation
func (otp HOTP) Counter() uint64 { counter := binary.BigEndian.Uint64(otp.counter[:]) return counter }
go
{ "resource": "" }
q173253
Increment
validation
func (otp HOTP) Increment() { for i := ctrSize - 1; i >= 0; i-- { if otp.counter[i]++; otp.counter[i] != 0 { return } } }
go
{ "resource": "" }
q173254
NewHOTP
validation
func NewHOTP(key []byte, counter uint64, digits int) *HOTP { otp := &HOTP{ Key: key, Digits: digits, } otp.counter = new([ctrSize]byte) binary.BigEndian.PutUint64(otp.counter[:], counter) return otp }
go
{ "resource": "" }
q173255
URL
validation
func (otp *HOTP) URL(label string) string { secret := base32.StdEncoding.EncodeToString(otp.Key) u := url.URL{} v := url.Values{} u.Scheme = "otpauth" u.Host = "hotp" u.Path = label v.Add("secret", secret) v.Add("counter", fmt.Sprintf("%d", otp.Counter())) u.RawQuery = v.Encode() return u.String() }
go
{ "resource": "" }
q173256
QR
validation
func (otp *HOTP) QR(label string) ([]byte, error) { u := otp.URL(label) code, err := qr.Encode(u, qr.Q) if err != nil { return nil, err } return code.PNG(), nil }
go
{ "resource": "" }
q173257
truncate
validation
func truncate(in []byte) int64 { offset := int(in[len(in)-1] & 0xF) p := in[offset : offset+4] var binCode int32 binCode = int32((p[0] & 0x7f)) << 24 binCode += int32((p[1] & 0xff)) << 16 binCode += int32((p[2] & 0xff)) << 8 binCode += int32((p[3] & 0xff)) return int64(binCode) & 0x7FFFFFFF }
go
{ "resource": "" }
q173258
FromURL
validation
func FromURL(urlString string) (*HOTP, string, error) { u, err := url.Parse(urlString) if err != nil { return nil, "", err } if u.Scheme != "otpauth" { return nil, "", ErrInvalidHOTPURL } else if u.Host != "hotp" { return nil, "", ErrInvalidHOTPURL } v := u.Query() if len(v) == 0 { return nil, "", Err...
go
{ "resource": "" }
q173259
GenerateHOTP
validation
func GenerateHOTP(digits int, randCounter bool) (*HOTP, error) { key := make([]byte, sha1.Size) _, err := io.ReadFull(PRNG, key) if err != nil { return nil, err } var counter uint64 if randCounter { ctr, err := rand.Int(PRNG, big.NewInt(int64(math.MaxInt64))) if err != nil { return nil, err } counte...
go
{ "resource": "" }
q173260
YubiKey
validation
func (otp *HOTP) YubiKey(in string) (string, string, bool) { if len(in) < otp.Digits { return "", "", false } otpStart := len(in) - otp.Digits code := in[otpStart:] pubid := in[:otpStart] return code, pubid, true }
go
{ "resource": "" }
q173261
IntegrityCheck
validation
func (otp *HOTP) IntegrityCheck() (string, uint64) { h := hmac.New(sha1.New, otp.Key) counter := make([]byte, 8) h.Write(counter) hash := h.Sum(nil) result := truncate(hash) mod := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(otp.Digits)), nil) mod = mod.Mod(big.NewInt(result), mod) fmtStr := fmt.Sprintf(...
go
{ "resource": "" }
q173262
Check
validation
func (otp *HOTP) Check(code string) bool { codeBytes := []byte(code) genCode := []byte(otp.OTP()) if subtle.ConstantTimeCompare(codeBytes, genCode) != 1 { otp.setCounter(otp.Counter() - 1) return false } return true }
go
{ "resource": "" }
q173263
Marshal
validation
func Marshal(otp *HOTP) ([]byte, error) { var asnHOTP struct { Key []byte Counter *big.Int Digits int } asnHOTP.Key = otp.Key[:] asnHOTP.Counter = new(big.Int).SetUint64(otp.Counter()) asnHOTP.Digits = otp.Digits return asn1.Marshal(asnHOTP) }
go
{ "resource": "" }
q173264
Unmarshal
validation
func Unmarshal(in []byte) (otp *HOTP, err error) { var asnHOTP struct { Key []byte Counter *big.Int Digits int } _, err = asn1.Unmarshal(in, &asnHOTP) if err != nil { return } otp = &HOTP{ Key: asnHOTP.Key[:], Digits: asnHOTP.Digits, } otp.setCounter(asnHOTP.Counter.Uint64()) return }
go
{ "resource": "" }
q173265
NewWriterPool
validation
func NewWriterPool(maxRate int, maxBurst time.Duration) *WriterPool { return &WriterPool{ maxRate: maxRate, maxBurst: maxBurst, givenOut: make(map[ThrottlerWriter]struct{}), } }
go
{ "resource": "" }
q173266
Get
validation
func (pool *WriterPool) Get(w io.Writer) (writer io.Writer, release func()) { // don't export a ThrottlerWriter to prevent users changing the rate // and expecting their change to be respected, since we might modify // the rate under their feet // make the initial rate be 0, the actual rate is // set in the call ...
go
{ "resource": "" }
q173267
Len
validation
func (pool *WriterPool) Len() int { pool.mu.Lock() l := len(pool.givenOut) pool.mu.Unlock() return l }
go
{ "resource": "" }
q173268
NewReaderPool
validation
func NewReaderPool(maxRate int, maxBurst time.Duration) *ReaderPool { return &ReaderPool{ maxRate: maxRate, maxBurst: maxBurst, givenOut: make(map[ThrottlerReader]struct{}), } }
go
{ "resource": "" }
q173269
Get
validation
func (pool *ReaderPool) Get(r io.Reader) (reader io.Reader, release func()) { // don't export a ThrottlerReader to prevent users changing the rate // and expecting their change to be respected, since we might modify // the rate under their feet // make the initial rate be 0, the actual rate is // set in the call ...
go
{ "resource": "" }
q173270
SetRate
validation
func (pool *ReaderPool) SetRate(rate int) int { pool.mu.Lock() old := pool.maxRate pool.maxRate = rate pool.setSharedRates() pool.mu.Unlock() return old }
go
{ "resource": "" }
q173271
Len
validation
func (pool *ReaderPool) Len() int { pool.mu.Lock() defer pool.mu.Unlock() return len(pool.givenOut) }
go
{ "resource": "" }
q173272
NewMeasuredWriter
validation
func NewMeasuredWriter(w io.Writer) *MeasuredWriter { return &MeasuredWriter{wrap: w, rate: newCounter()} }
go
{ "resource": "" }
q173273
BytesPerSec
validation
func (m *MeasuredWriter) BytesPerSec() uint64 { return uint64(m.rate.Rate(time.Second)) }
go
{ "resource": "" }
q173274
NewMeasuredReader
validation
func NewMeasuredReader(r io.Reader) *MeasuredReader { return &MeasuredReader{wrap: r, rate: newCounter()} }
go
{ "resource": "" }
q173275
BytesPer
validation
func (m *MeasuredReader) BytesPer(perPeriod time.Duration) uint64 { return uint64(m.rate.Rate(perPeriod)) }
go
{ "resource": "" }
q173276
BytesPerSec
validation
func (m *MeasuredReader) BytesPerSec() uint64 { return uint64(m.rate.Rate(time.Second)) }
go
{ "resource": "" }
q173277
ThrottledReader
validation
func ThrottledReader(r io.Reader, bytesPerSec int, maxBurst time.Duration) ThrottlerReader { return &throttledReader{ wrap: r, limiter: newRateLimiter(bytesPerSec, maxBurst), } }
go
{ "resource": "" }
q173278
ThrottledWriter
validation
func ThrottledWriter(w io.Writer, bytesPerSec int, maxBurst time.Duration) ThrottlerWriter { return &throttledWriter{ wrap: w, limiter: newRateLimiter(bytesPerSec, maxBurst), } }
go
{ "resource": "" }
q173279
NewDNSServer
validation
func NewDNSServer(domain string) *DNSServer { return &DNSServer{ Domain: domain + ".", aRecords: map[string]net.IP{}, srvRecords: map[string][]SRVRecord{}, aMutex: sync.RWMutex{}, srvMutex: sync.RWMutex{}, } }
go
{ "resource": "" }
q173280
qualifySrv
validation
func (ds *DNSServer) qualifySrv(service, protocol string) string { return fmt.Sprintf("_%s._%s.%s", service, protocol, ds.Domain) }
go
{ "resource": "" }
q173281
qualifySrvHosts
validation
func (ds *DNSServer) qualifySrvHosts(srvs []SRVRecord) []SRVRecord { newsrvs := []SRVRecord{} for _, srv := range srvs { newsrvs = append(newsrvs, SRVRecord{ Host: ds.qualifyHost(srv.Host), Port: srv.Port, }) } return newsrvs }
go
{ "resource": "" }
q173282
GetA
validation
func (ds *DNSServer) GetA(fqdn string) *dns.A { ds.aMutex.RLock() defer ds.aMutex.RUnlock() val, ok := ds.aRecords[fqdn] if ok { return &dns.A{ Hdr: dns.RR_Header{ Name: fqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, // 0 TTL results in UB for DNS resolvers and generally causes problems. ...
go
{ "resource": "" }
q173283
SetA
validation
func (ds *DNSServer) SetA(host string, ip net.IP) { ds.aMutex.Lock() ds.aRecords[ds.qualifyHost(host)] = ip ds.aMutex.Unlock() }
go
{ "resource": "" }
q173284
DeleteA
validation
func (ds *DNSServer) DeleteA(host string) { ds.aMutex.Lock() delete(ds.aRecords, ds.qualifyHost(host)) ds.aMutex.Unlock() }
go
{ "resource": "" }
q173285
SetSRV
validation
func (ds *DNSServer) SetSRV(service, protocol string, srvs []SRVRecord) { ds.srvMutex.Lock() ds.srvRecords[ds.qualifySrv(service, protocol)] = ds.qualifySrvHosts(srvs) ds.srvMutex.Unlock() }
go
{ "resource": "" }
q173286
DeleteSRV
validation
func (ds *DNSServer) DeleteSRV(service, protocol string) { ds.srvMutex.Lock() delete(ds.srvRecords, ds.qualifySrv(service, protocol)) ds.srvMutex.Unlock() }
go
{ "resource": "" }
q173287
Json
validation
func Json(data []byte) (Typed, error) { var m map[string]interface{} err := json.Unmarshal(data, &m) return Typed(m), err }
go
{ "resource": "" }
q173288
Must
validation
func Must(data []byte) Typed { var m map[string]interface{} if err := json.Unmarshal(data, &m); err != nil { panic(err) } return Typed(m) }
go
{ "resource": "" }
q173289
JsonReader
validation
func JsonReader(reader io.Reader) (Typed, error) { if data, err := ioutil.ReadAll(reader); err != nil { return nil, err } else { return Json(data) } }
go
{ "resource": "" }
q173290
JsonFile
validation
func JsonFile(path string) (Typed, error) { data, err := ioutil.ReadFile(path) if err != nil { return nil, err } return Json(data) }
go
{ "resource": "" }
q173291
JsonArray
validation
func JsonArray(data []byte) ([]Typed, error) { var m []interface{} err := json.Unmarshal(data, &m) if err != nil { return nil, err } l := len(m) if l == 0 { return nil, nil } typed := make([]Typed, l) for i := 0; i < l; i++ { value := m[i] if t, ok := value.(map[string]interface{}); ok { typed[i] = ...
go
{ "resource": "" }
q173292
JsonFileArray
validation
func JsonFileArray(path string) ([]Typed, error) { data, err := ioutil.ReadFile(path) if err != nil { return nil, err } return JsonArray(data) }
go
{ "resource": "" }
q173293
Bool
validation
func (t Typed) Bool(key string) bool { return t.BoolOr(key, false) }
go
{ "resource": "" }
q173294
BoolOr
validation
func (t Typed) BoolOr(key string, d bool) bool { if value, exists := t.BoolIf(key); exists { return value } return d }
go
{ "resource": "" }
q173295
BoolMust
validation
func (t Typed) BoolMust(key string) bool { b, exists := t.BoolIf(key) if exists == false { panic("expected boolean value for " + key) } return b }
go
{ "resource": "" }
q173296
BoolIf
validation
func (t Typed) BoolIf(key string) (bool, bool) { value, exists := t[key] if exists == false { return false, false } if n, ok := value.(bool); ok { return n, true } return false, false }
go
{ "resource": "" }
q173297
IntOr
validation
func (t Typed) IntOr(key string, d int) int { if value, exists := t.IntIf(key); exists { return value } return d }
go
{ "resource": "" }
q173298
IntMust
validation
func (t Typed) IntMust(key string) int { i, exists := t.IntIf(key) if exists == false { panic("expected int value for " + key) } return i }
go
{ "resource": "" }
q173299
IntIf
validation
func (t Typed) IntIf(key string) (int, bool) { value, exists := t[key] if exists == false { return 0, false } switch t := value.(type) { case int: return t, true case int16: return int(t), true case int32: return int(t), true case int64: return int(t), true case float64: return int(t), true case ...
go
{ "resource": "" }