_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q16800 | UnmarshalJSON | train | func (c *Client) UnmarshalJSON(b []byte) error {
temp := struct {
Config Config `json:"config"`
Cluster *Cluster `json:"cluster"`
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
c.Cluster = temp.Cluster
c.Config = temp.Config
return nil
} | go | {
"resource": ""
} |
q16801 | Get | train | func (c *Client) Get(endpoint string) (*RawResponse, error) {
return c.getCancelable(endpoint, nil)
} | go | {
"resource": ""
} |
q16802 | Put | train | func (c *Client) Put(endpoint string, body []byte) (*RawResponse, error) {
logger.Debug("put %s, %s, [%s]", endpoint, body, c.Cluster.Leader)
p := endpoint
req := NewRawRequest("PUT", p, body, nil)
resp, err := c.SendRequest(req)
if err != nil {
return nil, err
}
return resp, nil
} | go | {
"resource": ""
} |
q16803 | buildValues | train | func buildValues(value string, ttl uint64) url.Values {
v := url.Values{}
if value != "" {
v.Set("value", value)
}
if ttl > 0 {
v.Set("ttl", fmt.Sprintf("%v", ttl))
}
return v
} | go | {
"resource": ""
} |
q16804 | Encode | train | func (s Latin1) Encode() []byte {
e := charmap.Windows1252.NewEncoder()
es, _, err := transform.Bytes(e, s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16805 | Decode | train | func (s Latin1) Decode() []byte {
e := charmap.Windows1252.NewDecoder()
es, _, err := transform.Bytes(e, s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16806 | New | train | func New(n Name, data []byte) Body {
switch n {
case
AddrNPI,
AddrTON,
DataCoding,
DestAddrNPI,
DestAddrTON,
ESMClass,
ErrorCode,
InterfaceVersion,
MessageState,
NumberDests,
NoUnsuccess,
PriorityFlag,
ProtocolID,
RegisteredDelivery,
ReplaceIfPresentFlag,
SMDefaultMsgID,
SMLength,
... | go | {
"resource": ""
} |
q16807 | handlePDU | train | func (t *Transmitter) handlePDU(f HandlerFunc) {
for {
p, err := t.cl.Read()
if err != nil || p == nil {
break
}
seq := p.Header().Seq
t.tx.Lock()
rc := t.tx.inflight[seq]
t.tx.Unlock()
if rc != nil {
rc <- &tx{PDU: p}
} else if f != nil {
f(p)
}
if p.Header().ID == pdu.DeliverSMID { // ... | go | {
"resource": ""
} |
q16808 | newUnsucessDest | train | func newUnsucessDest(p pdufield.UnSme) UnsucessDest {
unDest := UnsucessDest{}
unDest.AddrTON, _ = p.Ton.Raw().(uint8) // if there is an error default value will be set
unDest.AddrNPI, _ = p.Npi.Raw().(uint8)
unDest.Address = string(p.DestAddr.Bytes())
unDest.Error = pdu.Status(binary.BigEndian.Uint32(p.ErrCode.By... | go | {
"resource": ""
} |
q16809 | Resp | train | func (sm *ShortMessage) Resp() pdu.Body {
sm.resp.Lock()
defer sm.resp.Unlock()
return sm.resp.p
} | go | {
"resource": ""
} |
q16810 | Submit | train | func (t *Transmitter) Submit(sm *ShortMessage) (*ShortMessage, error) {
if len(sm.DstList) > 0 || len(sm.DLs) > 0 {
// if we have a single destination address add it to the list
if sm.Dst != "" {
sm.DstList = append(sm.DstList, sm.Dst)
}
p := pdu.NewSubmitMulti(sm.TLVFields)
return t.submitMsgMulti(sm, p,... | go | {
"resource": ""
} |
q16811 | DecodeTLV | train | func DecodeTLV(r *bytes.Buffer) (Map, error) {
t := make(Map)
for r.Len() >= 4 {
b := r.Next(4)
ft := Tag(binary.BigEndian.Uint16(b[0:2]))
fl := binary.BigEndian.Uint16(b[2:4])
if r.Len() < int(fl) {
return nil, fmt.Errorf("not enough data for tag %s: want %d, have %d",
ft.Hex(), fl, r.Len())
}
b =... | go | {
"resource": ""
} |
q16812 | Bind | train | func (r *Receiver) Bind() <-chan ConnStatus {
r.cl.Lock()
defer r.cl.Unlock()
r.chanClose = make(chan struct{})
if r.cl.client != nil {
return r.cl.Status
}
c := &client{
Addr: r.Addr,
TLS: r.TLS,
EnquireLink: r.EnquireLink,
EnquireLinkTimeout: r.EnquireLinkTimeout... | go | {
"resource": ""
} |
q16813 | DecodeHeader | train | func DecodeHeader(r io.Reader) (*Header, error) {
b := make([]byte, HeaderLen)
_, err := io.ReadFull(r, b)
if err != nil {
return nil, err
}
l := binary.BigEndian.Uint32(b[0:4])
if l < HeaderLen {
return nil, fmt.Errorf("PDU too small: %d < %d", l, HeaderLen)
}
if l > MaxSize {
return nil, fmt.Errorf("PDU... | go | {
"resource": ""
} |
q16814 | SerializeTo | train | func (h *Header) SerializeTo(w io.Writer) error {
b := make([]byte, HeaderLen)
binary.BigEndian.PutUint32(b[0:4], h.Len)
binary.BigEndian.PutUint32(b[4:8], uint32(h.ID))
binary.BigEndian.PutUint32(b[8:12], uint32(h.Status))
binary.BigEndian.PutUint32(b[12:16], h.Seq)
_, err := w.Write(b)
return err
} | go | {
"resource": ""
} |
q16815 | NewGenericNACK | train | func NewGenericNACK() Body {
b := newGenericNACK(&Header{ID: GenericNACKID})
b.init()
return b
} | go | {
"resource": ""
} |
q16816 | NewBindReceiver | train | func NewBindReceiver() Body {
b := newBind(&Header{ID: BindReceiverID})
b.init()
return b
} | go | {
"resource": ""
} |
q16817 | NewBindTransceiver | train | func NewBindTransceiver() Body {
b := newBind(&Header{ID: BindTransceiverID})
b.init()
return b
} | go | {
"resource": ""
} |
q16818 | NewBindTransmitter | train | func NewBindTransmitter() Body {
b := newBind(&Header{ID: BindTransmitterID})
b.init()
return b
} | go | {
"resource": ""
} |
q16819 | NewBindReceiverResp | train | func NewBindReceiverResp() Body {
b := newBindResp(&Header{ID: BindReceiverRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16820 | NewBindTransceiverResp | train | func NewBindTransceiverResp() Body {
b := newBindResp(&Header{ID: BindTransceiverRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16821 | NewBindTransmitterResp | train | func NewBindTransmitterResp() Body {
b := newBindResp(&Header{ID: BindTransmitterRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16822 | NewQuerySM | train | func NewQuerySM() Body {
b := newQuerySM(&Header{ID: QuerySMID})
b.init()
return b
} | go | {
"resource": ""
} |
q16823 | NewQuerySMResp | train | func NewQuerySMResp() Body {
b := newQuerySMResp(&Header{ID: QuerySMRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16824 | NewSubmitSM | train | func NewSubmitSM(fields pdutlv.Fields) Body {
b := newSubmitSM(&Header{ID: SubmitSMID})
b.init()
for tag, value := range fields {
b.t.Set(tag, value)
}
return b
} | go | {
"resource": ""
} |
q16825 | NewSubmitSMResp | train | func NewSubmitSMResp() Body {
b := newSubmitSMResp(&Header{ID: SubmitSMRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16826 | NewSubmitMulti | train | func NewSubmitMulti(fields pdutlv.Fields) Body {
b := newSubmitMulti(&Header{ID: SubmitMultiID})
b.init()
for tag, value := range fields {
b.t.Set(tag, value)
}
return b
} | go | {
"resource": ""
} |
q16827 | NewSubmitMultiResp | train | func NewSubmitMultiResp() Body {
b := newSubmitMultiResp(&Header{ID: SubmitMultiRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16828 | NewDeliverSM | train | func NewDeliverSM() Body {
b := newDeliverSM(&Header{ID: DeliverSMID})
b.init()
return b
} | go | {
"resource": ""
} |
q16829 | NewDeliverSMResp | train | func NewDeliverSMResp() Body {
b := newDeliverSMResp(&Header{ID: DeliverSMRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16830 | NewDeliverSMRespSeq | train | func NewDeliverSMRespSeq(seq uint32) Body {
b := newDeliverSMResp(&Header{ID: DeliverSMRespID, Seq: seq})
b.init()
return b
} | go | {
"resource": ""
} |
q16831 | NewUnbind | train | func NewUnbind() Body {
b := newUnbind(&Header{ID: UnbindID})
b.init()
return b
} | go | {
"resource": ""
} |
q16832 | NewUnbindResp | train | func NewUnbindResp() Body {
b := newUnbindResp(&Header{ID: UnbindRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16833 | NewEnquireLink | train | func NewEnquireLink() Body {
b := newEnquireLink(&Header{ID: EnquireLinkID})
b.init()
return b
} | go | {
"resource": ""
} |
q16834 | NewEnquireLinkResp | train | func NewEnquireLinkResp() Body {
b := newEnquireLinkResp(&Header{ID: EnquireLinkRespID})
b.init()
return b
} | go | {
"resource": ""
} |
q16835 | NewEnquireLinkRespSeq | train | func NewEnquireLinkRespSeq(seq uint32) Body {
b := newEnquireLinkResp(&Header{ID: EnquireLinkRespID, Seq: seq})
b.init()
return b
} | go | {
"resource": ""
} |
q16836 | NewTLV | train | func NewTLV(tag Tag, value []byte) Body {
return &Field{ Tag: tag, Data: value }
} | go | {
"resource": ""
} |
q16837 | Dial | train | func Dial(addr string, TLS *tls.Config) (Conn, error) {
if addr == "" {
addr = "localhost:2775"
}
fd, err := net.Dial("tcp", addr)
if err != nil {
return nil, err
}
if TLS != nil {
fd = tls.Client(fd, TLS)
}
c := &conn{
rwc: fd,
r: bufio.NewReader(fd),
w: bufio.NewWriter(fd),
}
return c, nil
} | go | {
"resource": ""
} |
q16838 | Set | train | func (cs *connSwitch) Set(c Conn) {
cs.mu.Lock()
if cs.c != nil {
cs.c.Close()
}
cs.c = c
cs.mu.Unlock()
} | go | {
"resource": ""
} |
q16839 | Close | train | func (cs *connSwitch) Close() error {
cs.mu.Lock()
defer cs.mu.Unlock()
if cs.c == nil {
return ErrNotConnected
}
err := cs.c.Close()
cs.c = nil
return err
} | go | {
"resource": ""
} |
q16840 | Bind | train | func (t *Transceiver) Bind() <-chan ConnStatus {
t.r = rand.New(rand.NewSource(time.Now().UnixNano()))
t.cl.Lock()
defer t.cl.Unlock()
if t.cl.client != nil {
return t.cl.Status
}
t.tx.Lock()
t.tx.inflight = make(map[uint32]chan *tx)
t.tx.Unlock()
c := &client{
Addr: t.Addr,
TLS: ... | go | {
"resource": ""
} |
q16841 | init | train | func (pdu *codec) init() {
if pdu.l == nil {
pdu.l = pdufield.List{}
}
pdu.f = make(pdufield.Map)
pdu.t = make(pdutlv.Map)
if pdu.h.Seq == 0 { // If Seq not set
pdu.h.Seq = atomic.AddUint32(&nextSeq, 1)
}
} | go | {
"resource": ""
} |
q16842 | setup | train | func (pdu *codec) setup(f pdufield.Map, t pdutlv.Map) {
pdu.f, pdu.t = f, t
} | go | {
"resource": ""
} |
q16843 | Len | train | func (pdu *codec) Len() int {
l := HeaderLen
for _, f := range pdu.f {
l += f.Len()
}
for _, t := range pdu.t {
l += t.Len()
}
return l
} | go | {
"resource": ""
} |
q16844 | SerializeTo | train | func (pdu *codec) SerializeTo(w io.Writer) error {
var b bytes.Buffer
for _, k := range pdu.FieldList() {
f, ok := pdu.f[k]
if !ok {
pdu.f.Set(k, nil)
f = pdu.f[k]
}
if err := f.SerializeTo(&b); err != nil {
return err
}
}
for _, f := range pdu.TLVFields() {
if err := f.SerializeTo(&b); err != ... | go | {
"resource": ""
} |
q16845 | Encode | train | func (s ISO88595) Encode() []byte {
e := charmap.ISO8859_5.NewEncoder()
es, _, err := transform.Bytes(e, s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16846 | Decode | train | func (s ISO88595) Decode() []byte {
e := charmap.ISO8859_5.NewDecoder()
es, _, err := transform.Bytes(e, s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16847 | Hex | train | func (t Tag) Hex() string {
bin := make([]byte, 2, 2)
binary.BigEndian.PutUint16(bin, uint16(t))
return hex.EncodeToString(bin)
} | go | {
"resource": ""
} |
q16848 | Encode | train | func (s UCS2) Encode() []byte {
e := unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
es, _, err := transform.Bytes(e.NewEncoder(), s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16849 | Decode | train | func (s UCS2) Decode() []byte {
e := unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
es, _, err := transform.Bytes(e.NewDecoder(), s)
if err != nil {
return s
}
return es
} | go | {
"resource": ""
} |
q16850 | ValidateGSM7String | train | func ValidateGSM7String(text string) []rune {
invalidChars := make([]rune, 0, 4)
for _, r := range text {
if _, ok := forwardLookup[r]; !ok {
if _, ok := forwardEscape[r]; !ok {
invalidChars = append(invalidChars, r)
}
}
}
return invalidChars
} | go | {
"resource": ""
} |
q16851 | ValidateGSM7Buffer | train | func ValidateGSM7Buffer(buffer []byte) []byte {
invalidBytes := make([]byte, 0, 4)
count := 0
for count < len(buffer) {
b := buffer[count]
if b == escapeSequence {
count++
if count >= len(buffer) {
invalidBytes = append(invalidBytes, b)
break
}
e := buffer[count]
if _, ok := reverseEscape[... | go | {
"resource": ""
} |
q16852 | Bind | train | func (c *client) Bind() {
delay := 1.0
const maxdelay = 120.0
for !c.closed() {
eli := make(chan struct{})
c.inbox = make(chan pdu.Body)
conn, err := Dial(c.Addr, c.TLS)
if err != nil {
c.notify(&connStatus{
s: ConnectionFailed,
err: err,
})
goto retry
}
c.conn.Set(conn)
if err = c.B... | go | {
"resource": ""
} |
q16853 | Read | train | func (c *client) Read() (pdu.Body, error) {
select {
case pdu := <-c.inbox:
return pdu, nil
case <-c.stop:
return nil, io.EOF
}
} | go | {
"resource": ""
} |
q16854 | Write | train | func (c *client) Write(w pdu.Body) error {
if c.RateLimiter != nil {
c.RateLimiter.Wait(c.lmctx)
}
return c.conn.Write(w)
} | go | {
"resource": ""
} |
q16855 | Close | train | func (c *client) Close() error {
c.once.Do(func() {
close(c.stop)
if err := c.conn.Write(pdu.NewUnbind()); err == nil {
select {
case <-c.inbox: // TODO: validate UnbindResp
case <-time.After(time.Second):
}
}
c.conn.Close()
})
return nil
} | go | {
"resource": ""
} |
q16856 | trysleep | train | func (c *client) trysleep(d time.Duration) {
select {
case <-time.After(d):
case <-c.stop:
}
} | go | {
"resource": ""
} |
q16857 | respTimeout | train | func (c *client) respTimeout() <-chan time.Time {
if c.RespTimeout == 0 {
return time.After(time.Second)
}
return time.After(c.RespTimeout)
} | go | {
"resource": ""
} |
q16858 | bind | train | func bind(c Conn, p pdu.Body) (pdu.Body, error) {
f := p.Fields()
f.Set(pdufield.InterfaceVersion, 0x34)
err := c.Write(p)
if err != nil {
return nil, err
}
resp, err := c.Read()
if err != nil {
return nil, err
}
h := resp.Header()
if h.Status != 0 {
return nil, h.Status
}
return resp, nil
} | go | {
"resource": ""
} |
q16859 | Encode | train | func Encode(structPtr interface{}) (bytes []byte, err error) {
defer func() {
if e := recover(); e != nil {
err = errors.New(e.(string))
bytes = nil
}
}()
if structPtr == nil {
return nil, nil
}
if bu, ok := structPtr.(encoding.BinaryMarshaler); ok {
return bu.MarshalBinary()
}
en := encoder{}
v... | go | {
"resource": ""
} |
q16860 | GenerateProtobufDefinition | train | func GenerateProtobufDefinition(w io.Writer, types []interface{}, enumMap EnumMap, renamer GeneratorNamer) (err error) {
defer func() {
if e := recover(); e != nil {
err = errors.New(e.(string))
}
}()
enums := enumTypeMap{}
for name, value := range enumMap {
v := reflect.ValueOf(value)
t := v.Type()
if... | go | {
"resource": ""
} |
q16861 | String | train | func (c *Constructors) String() string {
var s string
for k := range *c {
s += k.String() + "=>" + "(func() interface {})" + "\t"
}
return s
} | go | {
"resource": ""
} |
q16862 | DecodeWithConstructors | train | func DecodeWithConstructors(buf []byte, structPtr interface{}, cons Constructors) (err error) {
defer func() {
if r := recover(); r != nil {
switch e := r.(type) {
case string:
err = errors.New(e)
case error:
err = e
default:
err = errors.New("Failed to decode the field")
}
}
}()
if st... | go | {
"resource": ""
} |
q16863 | message | train | func (de *decoder) message(buf []byte, sval reflect.Value) error {
if sval.Kind() != reflect.Struct {
return errors.New("not a struct")
}
// Decode all the fields
fields := ProtoFields(sval.Type())
fieldi := 0
for len(buf) > 0 {
// Parse the key
key, n := binary.Uvarint(buf)
if n <= 0 {
return errors.N... | go | {
"resource": ""
} |
q16864 | value | train | func (de *decoder) value(wiretype int, buf []byte,
val reflect.Value) ([]byte, error) {
// Break out the value from the buffer based on the wire type
var v uint64
var n int
var vb []byte
switch wiretype {
case 0: // varint
v, n = binary.Uvarint(buf)
if n <= 0 {
return nil, errors.New("bad protobuf varint... | go | {
"resource": ""
} |
q16865 | instantiate | train | func (de *decoder) instantiate(t reflect.Type) reflect.Value {
// If it's an interface type, lookup a dynamic constructor for it.
if t.Kind() == reflect.Interface {
newfunc, ok := de.nm[t]
if !ok {
panic("no constructor for interface " + t.String())
}
return reflect.ValueOf(newfunc())
}
// Otherwise, f... | go | {
"resource": ""
} |
q16866 | slice | train | func (de *decoder) slice(slval reflect.Value, vb []byte) error {
// Find the element type, and create a temporary instance of it.
eltype := slval.Type().Elem()
val := reflect.New(eltype).Elem()
// Decide on the wiretype to use for decoding.
var wiretype int
switch eltype.Kind() {
case reflect.Bool, reflect.Int3... | go | {
"resource": ""
} |
q16867 | register | train | func (ir *generatorRegistry) register(g InterfaceGeneratorFunc) {
val, ok := g().(InterfaceMarshaler)
if !ok {
panic("Implementation of the interface must fulfilled InterfaceMarshaler")
}
key := val.MarshalID()
ir.generators[key] = g
} | go | {
"resource": ""
} |
q16868 | get | train | func (ir *generatorRegistry) get(key GeneratorID) InterfaceGeneratorFunc {
g, _ := ir.generators[key]
return g
} | go | {
"resource": ""
} |
q16869 | WriteFile | train | func WriteFile(f *File, root string) (string, error) {
if f.Encoding != "" {
return "", fmt.Errorf("Unable to write file with encoding %s", f.Encoding)
}
fullpath := path.Join(root, f.Path)
dir := path.Dir(fullpath)
log.Printf("Writing file to %q", fullpath)
if err := EnsureDirectoryExists(dir); err != nil {
... | go | {
"resource": ""
} |
q16870 | AuthorizeSSHKeys | train | func AuthorizeSSHKeys(user string, keysName string, keys []string) error {
for i, key := range keys {
keys[i] = strings.TrimSpace(key)
}
// join all keys with newlines, ensuring the resulting string
// also ends with a newline
joined := fmt.Sprintf("%s\n", strings.Join(keys, "\n"))
cmd := exec.Command("update... | go | {
"resource": ""
} |
q16871 | Error | train | func (r *Report) Error(line int, message string) {
r.entries = append(r.entries, Entry{entryError, message, line})
} | go | {
"resource": ""
} |
q16872 | Warning | train | func (r *Report) Warning(line int, message string) {
r.entries = append(r.entries, Entry{entryWarning, message, line})
} | go | {
"resource": ""
} |
q16873 | Info | train | func (r *Report) Info(line int, message string) {
r.entries = append(r.entries, Entry{entryInfo, message, line})
} | go | {
"resource": ""
} |
q16874 | String | train | func (e Entry) String() string {
return fmt.Sprintf("line %d: %s: %s", e.line, e.kind, e.message)
} | go | {
"resource": ""
} |
q16875 | MarshalJSON | train | func (e Entry) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"kind": e.kind.String(),
"message": e.message,
"line": e.line,
})
} | go | {
"resource": ""
} |
q16876 | PlaceUnit | train | func (s *systemd) PlaceUnit(u Unit) error {
file := File{config.File{
Path: u.Destination(s.root),
Content: u.Content,
RawFilePermissions: "0644",
}}
_, err := WriteFile(&file, "/")
return err
} | go | {
"resource": ""
} |
q16877 | PlaceUnitDropIn | train | func (s *systemd) PlaceUnitDropIn(u Unit, d config.UnitDropIn) error {
file := File{config.File{
Path: u.DropInDestination(s.root, d),
Content: d.Content,
RawFilePermissions: "0644",
}}
_, err := WriteFile(&file, "/")
return err
} | go | {
"resource": ""
} |
q16878 | Child | train | func (n node) Child(name string) node {
for _, c := range n.children {
if c.name == name {
return c
}
}
return node{}
} | go | {
"resource": ""
} |
q16879 | HumanType | train | func (n node) HumanType() string {
switch k := n.Kind(); k {
case reflect.Slice:
c := n.Type().Elem()
return "[]" + node{Value: reflect.New(c).Elem()}.HumanType()
default:
return k.String()
}
} | go | {
"resource": ""
} |
q16880 | NewNode | train | func NewNode(value interface{}, context context) node {
var n node
toNode(value, context, &n)
return n
} | go | {
"resource": ""
} |
q16881 | findKey | train | func findKey(key string, context context) (context, bool) {
return find(yamlKey, key, context)
} | go | {
"resource": ""
} |
q16882 | WriteEnvFile | train | func WriteEnvFile(ef *EnvFile, root string) error {
// validate new keys, mergeEnvContents uses pending to track writes
pending := make(map[string]string, len(ef.Vars))
for key, value := range ef.Vars {
if !validKey.MatchString(key) {
return fmt.Errorf("Invalid name %q for %s", key, ef.Path)
}
pending[key] ... | go | {
"resource": ""
} |
q16883 | keys | train | func keys(m map[string]string) (s []string) {
for k := range m {
s = append(s, k)
}
sort.Strings(s)
return
} | go | {
"resource": ""
} |
q16884 | Units | train | func (fe Fleet) Units() []Unit {
return []Unit{{config.Unit{
Name: "fleet.service",
Runtime: true,
DropIns: []config.UnitDropIn{{
Name: "20-cloudinit.conf",
Content: serviceContents(fe.Fleet),
}},
}}}
} | go | {
"resource": ""
} |
q16885 | serviceContents | train | func serviceContents(e interface{}) string {
vars := getEnvVars(e)
if len(vars) == 0 {
return ""
}
out := "[Service]\n"
for _, v := range vars {
out += fmt.Sprintf("Environment=\"%s\"\n", v)
}
return out
} | go | {
"resource": ""
} |
q16886 | Units | train | func (ee Locksmith) Units() []Unit {
return []Unit{{config.Unit{
Name: "locksmithd.service",
Runtime: true,
DropIns: []config.UnitDropIn{{
Name: "20-cloudinit.conf",
Content: serviceContents(ee.Locksmith),
}},
}}}
} | go | {
"resource": ""
} |
q16887 | GetRetry | train | func (h *HttpClient) GetRetry(rawurl string) ([]byte, error) {
if rawurl == "" {
return nil, ErrInvalid{errors.New("URL is empty. Skipping.")}
}
url, err := neturl.Parse(rawurl)
if err != nil {
return nil, ErrInvalid{err}
}
// Unfortunately, url.Parse is too generic to throw errors if a URL does not
// hav... | go | {
"resource": ""
} |
q16888 | Apply | train | func (e *Environment) Apply(data string) string {
for key, val := range e.substitutions {
matchKey := strings.Replace(key, `$`, `\$`, -1)
replKey := strings.Replace(key, `$`, `$$`, -1)
// "key" -> "val"
data = regexp.MustCompile(`([^\\]|^)`+matchKey).ReplaceAllString(data, `${1}`+val)
// "\key" -> "key"
d... | go | {
"resource": ""
} |
q16889 | checkDiscoveryUrl | train | func checkDiscoveryUrl(cfg node, report *Report) {
c := cfg.Child("coreos").Child("etcd").Child("discovery")
if !c.IsValid() {
return
}
if _, err := url.ParseRequestURI(c.String()); err != nil {
report.Warning(c.line, "discovery URL is not valid")
}
} | go | {
"resource": ""
} |
q16890 | checkEncoding | train | func checkEncoding(cfg node, report *Report) {
for _, f := range cfg.Child("write_files").children {
e := f.Child("encoding")
if !e.IsValid() {
continue
}
c := f.Child("content")
if _, err := config.DecodeContent(c.String(), e.String()); err != nil {
report.Error(c.line, fmt.Sprintf("content cannot be... | go | {
"resource": ""
} |
q16891 | checkStructure | train | func checkStructure(cfg node, report *Report) {
g := NewNode(config.CloudConfig{}, NewContext([]byte{}))
checkNodeStructure(cfg, g, report)
} | go | {
"resource": ""
} |
q16892 | isCompatible | train | func isCompatible(n, g reflect.Kind) bool {
switch g {
case reflect.String:
return n == reflect.String || n == reflect.Int || n == reflect.Float64 || n == reflect.Bool
case reflect.Struct:
return n == reflect.Struct || n == reflect.Map
case reflect.Float64:
return n == reflect.Float64 || n == reflect.Int
cas... | go | {
"resource": ""
} |
q16893 | getDatasources | train | func getDatasources() []datasource.Datasource {
dss := make([]datasource.Datasource, 0, 5)
if flags.sources.file != "" {
dss = append(dss, file.NewDatasource(flags.sources.file))
}
if flags.sources.url != "" {
dss = append(dss, url.NewDatasource(flags.sources.url))
}
if flags.sources.configDrive != "" {
dss... | go | {
"resource": ""
} |
q16894 | selectDatasource | train | func selectDatasource(sources []datasource.Datasource) datasource.Datasource {
ds := make(chan datasource.Datasource)
stop := make(chan struct{})
var wg sync.WaitGroup
for _, s := range sources {
wg.Add(1)
go func(s datasource.Datasource) {
defer wg.Done()
duration := datasourceInterval
for {
log... | go | {
"resource": ""
} |
q16895 | Decode | train | func (cc *CloudConfig) Decode() error {
for i, file := range cc.WriteFiles {
content, err := DecodeContent(file.Content, file.Encoding)
if err != nil {
return err
}
cc.WriteFiles[i].Content = string(content)
cc.WriteFiles[i].Encoding = ""
}
return nil
} | go | {
"resource": ""
} |
q16896 | AssertStructValid | train | func AssertStructValid(c interface{}) error {
ct := reflect.TypeOf(c)
cv := reflect.ValueOf(c)
for i := 0; i < ct.NumField(); i++ {
ft := ct.Field(i)
if !isFieldExported(ft) {
continue
}
if err := AssertValid(cv.Field(i), ft.Tag.Get("valid")); err != nil {
err.Field = ft.Name
return err
}
}
ret... | go | {
"resource": ""
} |
q16897 | AssertValid | train | func AssertValid(value reflect.Value, valid string) *ErrorValid {
if valid == "" || isZero(value) {
return nil
}
vs := fmt.Sprintf("%v", value.Interface())
if m, _ := regexp.MatchString(valid, vs); m {
return nil
}
return &ErrorValid{
Value: vs,
Valid: valid,
}
} | go | {
"resource": ""
} |
q16898 | Validate | train | func Validate(userdataBytes []byte) (Report, error) {
switch {
case len(userdataBytes) == 0:
return Report{}, nil
case config.IsScript(string(userdataBytes)):
return Report{}, nil
case config.IsIgnitionConfig(string(userdataBytes)):
return Report{}, nil
case config.IsCloudConfig(string(userdataBytes)):
ret... | go | {
"resource": ""
} |
q16899 | validateCloudConfig | train | func validateCloudConfig(config []byte, rules []rule) (report Report, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
}
}()
c, err := parseCloudConfig(config, &report)
if err != nil {
return report, err
}
for _, r := range rules {
r(c, &report)
}
return report, n... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.