_id
stringlengths 2
7
| title
stringlengths 1
118
| partition
stringclasses 3
values | text
stringlengths 52
85.5k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q182700 | Auth | test | func (s *FakeVCDClient) Auth(username, password string) (err error) {
return s.ErrAuthFake
} | go | {
"resource": ""
} |
q182701 | QueryTemplate | test | func (s *FakeVCDClient) QueryTemplate(templateName string) (vappTemplate *vcloudclient.VAppTemplateRecord, err error) {
return s.FakeVAppTemplateRecord, s.ErrDeployFake
} | go | {
"resource": ""
} |
q182702 | NewEncoder | test | func NewEncoder(w io.Writer) Encoder {
return versionOneEncoder{w, make([]byte, 9), bytes.NewBuffer(make([]byte, 0, 4096))}
} | go | {
"resource": ""
} |
q182703 | Getter | test | func Getter(g NonceGetter) Option {
return Option{func(o *options) {
o.getter = g
}}
} | go | {
"resource": ""
} |
q182704 | Setter | test | func Setter(s NonceSetter) Option {
return Option{func(o *options) {
o.setter = s
}}
} | go | {
"resource": ""
} |
q182705 | Age | test | func Age(age time.Duration) Option {
return Option{func(o *options) {
o.age = age
}}
} | go | {
"resource": ""
} |
q182706 | Nonce | test | func Nonce(h http.Handler, opts ...Option) http.Handler {
headerStorage := nonceHeaderStorage{}
o := options{
logger: handler.OutLogger(),
generator: timeRandomGenerator,
getter: headerStorage,
setter: headerStorage,
age: 45 * time.Second,
}
o.apply(opts)
store := nonceStore{}
opChan := make(chan func(nonceStore))
go func() {
for op := range opChan {
op(store)
}
}()
go func() {
for {
select {
case <-time.After(5 * time.Minute):
cleanup(o.age, opChan)
}
}
}()
setter := func(w http.ResponseWriter, r *http.Request) error {
nonce, err := generateAndStore(o.age, o.generator, opChan)
if err != nil {
return err
}
return o.setter.SetNonce(nonce, w, r)
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
nonce := o.getter.GetNonce(r)
if nonce != "" {
if validateAndRemoveNonce(nonce, o.age, opChan) {
ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceValid})
} else {
ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceInvalid})
}
}
h.ServeHTTP(w, r.WithContext(context.WithValue(ctx, nonceSetterKey, setter)))
})
} | go | {
"resource": ""
} |
q182707 | NonceValueFromRequest | test | func NonceValueFromRequest(r *http.Request) NonceStatus {
if c := r.Context().Value(nonceValueKey); c != nil {
if v, ok := c.(NonceStatus); ok {
return v
}
}
return NonceStatus{NonceNotRequested}
} | go | {
"resource": ""
} |
q182708 | StoreNonce | test | func StoreNonce(w http.ResponseWriter, r *http.Request) (err error) {
if c := r.Context().Value(nonceSetterKey); c != nil {
if setter, ok := c.(func(http.ResponseWriter, *http.Request) error); ok {
err = setter(w, r)
}
}
return err
} | go | {
"resource": ""
} |
q182709 | PutFloat32Array | test | func (b *TupleBuilder) PutFloat32Array(field string, value []float32) (wrote int, err error) {
// field type should be
if err = b.typeCheck(field, Float32ArrayField); err != nil {
return 0, err
}
size := len(value)
if size < math.MaxUint8 {
if b.available() < size*4+2 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+2, value)
// write type code
b.buffer[b.pos] = byte(FloatArray8Code.OpCode)
// write length
b.buffer[b.pos+1] = byte(size)
wrote += size + 2
} else if size < math.MaxUint16 {
if b.available() < size*4+3 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size))
// write value
xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+3, value)
// write type code
b.buffer[b.pos] = byte(FloatArray16Code.OpCode)
wrote += 3 + size
} else if size < math.MaxUint32 {
if b.available() < size*4+5 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size))
// write value
xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+5, value)
// write type code
b.buffer[b.pos] = byte(FloatArray32Code.OpCode)
wrote += 5 + size
} else {
if b.available() < size*4+9 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size))
// write value
xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+9, value)
// write type code
b.buffer[b.pos] = byte(FloatArray64Code.OpCode)
wrote += 9 + size
}
b.offsets[field] = b.pos
b.pos += wrote
return
} | go | {
"resource": ""
} |
q182710 | PutFloat64Array | test | func (b *TupleBuilder) PutFloat64Array(field string, value []float64) (wrote int, err error) {
// field type should be
if err = b.typeCheck(field, Float64ArrayField); err != nil {
return 0, err
}
size := len(value)
if size < math.MaxUint8 {
if b.available() < size*8+2 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+2, value)
// write type code
b.buffer[b.pos] = byte(DoubleArray8Code.OpCode)
// write length
b.buffer[b.pos+1] = byte(size)
wrote += size + 2
} else if size < math.MaxUint16 {
if b.available() < size*8+3 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size))
// write value
xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+3, value)
// write type code
b.buffer[b.pos] = byte(DoubleArray16Code.OpCode)
wrote += 3 + size
} else if size < math.MaxUint32 {
if b.available() < size*8+5 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size))
// write value
xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+5, value)
// write type code
b.buffer[b.pos] = byte(DoubleArray32Code.OpCode)
wrote += 5 + size
} else {
if b.available() < size*8+9 {
return 0, xbinary.ErrOutOfRange
}
// write length
xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size))
// write value
xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+9, value)
// write type code
b.buffer[b.pos] = byte(DoubleArray64Code.OpCode)
wrote += 9 + size
}
b.offsets[field] = b.pos
b.pos += wrote
return
} | go | {
"resource": ""
} |
q182711 | Do | test | func (s *ClientDoer) Do(req *http.Request) (resp *http.Response, err error) {
s.SpyRequest = *req
return s.Response, s.Error
} | go | {
"resource": ""
} |
q182712 | NewLease | test | func NewLease(taskCollection integrations.Collection, availableSkus map[string]skurepo.SkuBuilder) *Lease {
return &Lease{
taskCollection: taskCollection,
taskManager: taskmanager.NewTaskManager(taskCollection),
availableSkus: availableSkus,
Task: taskmanager.RedactedTask{},
}
} | go | {
"resource": ""
} |
q182713 | Delete | test | func (s *Lease) Delete(logger *log.Logger, req *http.Request) (statusCode int, response interface{}) {
var (
err error
)
statusCode = http.StatusNotFound
s.taskCollection.Wake()
if err = s.InitFromHTTPRequest(req); err == nil {
logger.Println("restocking inventory...")
s.ReStock()
statusCode = http.StatusAccepted
response = s.Task
} else {
response = map[string]string{"error": err.Error()}
}
return
} | go | {
"resource": ""
} |
q182714 | Post | test | func (s *Lease) Post(logger *log.Logger, req *http.Request) (statusCode int, response interface{}) {
var (
err error
)
statusCode = http.StatusNotFound
s.taskCollection.Wake()
logger.Println("collection dialed successfully")
if err = s.InitFromHTTPRequest(req); err == nil {
logger.Println("obtaining lease...", s)
s.Procurement()
statusCode = http.StatusCreated
response = s.Task
} else {
response = map[string]string{"error": err.Error()}
}
return
} | go | {
"resource": ""
} |
q182715 | ReStock | test | func (s *Lease) ReStock() (skuTask *taskmanager.Task) {
if skuConstructor, ok := s.availableSkus[s.Sku]; ok {
leaseMap := structs.Map(s)
sku := skuConstructor.New(s.taskManager, leaseMap)
skuTask = sku.ReStock()
s.Task = skuTask.GetRedactedVersion()
} else {
s.Task.Status = TaskStatusUnavailable
}
return
} | go | {
"resource": ""
} |
q182716 | Procurement | test | func (s *Lease) Procurement() (skuTask *taskmanager.Task) {
if skuConstructor, ok := s.availableSkus[s.Sku]; ok {
leaseMap := structs.Map(s)
sku := skuConstructor.New(s.taskManager, leaseMap)
GLogger.Println("here is my sku: ", sku)
skuTask = sku.Procurement()
tt := skuTask.Read(func(t *taskmanager.Task) interface{} {
tt := *t
return tt
})
GLogger.Println("here is my task after procurement: ", tt)
s.Task = skuTask.GetRedactedVersion()
} else {
GLogger.Println("No Sku Match: ", s.Sku, s.availableSkus)
s.Task.Status = TaskStatusUnavailable
}
return
} | go | {
"resource": ""
} |
q182717 | InitFromHTTPRequest | test | func (s *Lease) InitFromHTTPRequest(req *http.Request) (err error) {
if req.Body != nil {
if body, err := ioutil.ReadAll(req.Body); err == nil {
if err = json.Unmarshal(body, s); err != nil {
GLogger.Println(err)
}
}
} else {
err = ErrEmptyBody
}
if s.ProcurementMeta == nil {
s.ProcurementMeta = make(map[string]interface{})
}
return
} | go | {
"resource": ""
} |
q182718 | Is | test | func (t *Tuple) Is(tupleType TupleType) bool {
return t.Header.Hash == tupleType.Hash && t.Header.NamespaceHash == tupleType.NamespaceHash
} | go | {
"resource": ""
} |
q182719 | Offset | test | func (t *Tuple) Offset(field string) (int, error) {
index, exists := t.Header.Type.Offset(field)
if !exists {
return 0, ErrFieldDoesNotExist
}
// Tuple type and tuple header do not agree on fields
if index < 0 || index >= int(t.Header.FieldCount) {
return 0, ErrInvalidFieldIndex
}
return int(t.Header.Offsets[index]), nil
} | go | {
"resource": ""
} |
q182720 | WriteTo | test | func (t Tuple) WriteTo(w io.Writer) (n int, err error) {
// write header
wrote, err := t.Header.WriteTo(w)
if err != nil {
return int(wrote), nil
}
n, err = w.Write(t.data)
if err != nil {
return int(n), err
}
return int(wrote) + n, nil
} | go | {
"resource": ""
} |
q182721 | PutTuple | test | func (b *TupleBuilder) PutTuple(field string, value Tuple) (wrote int, err error) {
// field type should be
if err = b.typeCheck(field, TupleField); err != nil {
return 0, err
}
size := value.Size() + value.Header.Size()
if size < math.MaxUint8 {
// check length
if b.available() < size+2 {
return 0, xbinary.ErrOutOfRange
}
// write type code
b.buffer[b.pos] = byte(Tuple8Code.OpCode)
// write length
b.buffer[b.pos+1] = byte(size)
wrote += 2
// Write tuple
n, err := b.writeTuple(value, b.pos+wrote, size)
wrote += int(n)
// Return err
if err != nil {
return 0, err
}
} else if size < math.MaxUint16 {
// check length
if b.available() < size+3 {
return 0, xbinary.ErrOutOfRange
}
// write type code
b.buffer[b.pos] = byte(Tuple16Code.OpCode)
// write length
xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size))
wrote += 3
// write tuple
n, err := b.writeTuple(value, b.pos+wrote, size)
// n, err := value.WriteAt(&b.buffer, int64(b.pos+3))
wrote += int(n)
// Return err
if err != nil {
return 0, err
}
} else if size < math.MaxUint32 {
// check length
if b.available() < size+5 {
return 0, xbinary.ErrOutOfRange
}
// write type code
b.buffer[b.pos] = byte(Tuple32Code.OpCode)
// write length
xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size))
wrote += 5
// write tuple
n, err := b.writeTuple(value, b.pos+wrote, size)
// n, err := value.WriteAt(&b.buffer, int64(b.pos+5))
wrote += int(n)
// Return err
if err != nil {
return 0, err
}
} else {
// check length
if b.available() < size+9 {
return 0, xbinary.ErrOutOfRange
}
// write type code
b.buffer[b.pos] = byte(Tuple64Code.OpCode)
// write length
xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size))
wrote += 9
// write tuple
n, err := b.writeTuple(value, b.pos+wrote, size)
// n, err := value.WriteAt(&b.buffer, int64(b.pos+9))
wrote += int(n)
// Return err
if err != nil {
return 0, err
}
}
// store offset and increment position
b.offsets[field] = b.pos
b.pos += wrote
return
} | go | {
"resource": ""
} |
q182722 | WriteString | test | func (ctx *Cotex) WriteString(content string) {
ctx.ResponseWriter.Write([]byte(content))
} | go | {
"resource": ""
} |
q182723 | NotFound | test | func (ctx *Cotex) NotFound(message string) {
ctx.ResponseWriter.WriteHeader(404)
ctx.ResponseWriter.Write([]byte(message))
} | go | {
"resource": ""
} |
q182724 | Run | test | func (s *Agent) Run(process func(*Agent) error) {
s.task.Update(func(t *Task) interface{} {
t.taskManager = s.taskManager
t.Status = AgentTaskStatusRunning
return t
})
s.statusEmitter <- AgentTaskStatusRunning
go s.startTaskPoller()
go s.listenForPoll()
go func(agent Agent) {
s := &agent
s.processExitHanderlDecorate(process)
<-s.processComplete
}(*s)
} | go | {
"resource": ""
} |
q182725 | NewWaitGroup | test | func NewWaitGroup(throttle int) *WaitGroup {
return &WaitGroup{
outstanding: 0,
throttle: throttle,
completed: make(chan bool, throttle),
}
} | go | {
"resource": ""
} |
q182726 | Add | test | func (w *WaitGroup) Add() {
w.outstanding++
if w.outstanding > w.throttle {
select {
case <-w.completed:
w.outstanding--
return
}
}
} | go | {
"resource": ""
} |
q182727 | Wait | test | func (w *WaitGroup) Wait() {
if w.outstanding == 0 {
return
}
for w.outstanding > 0 {
select {
case <-w.completed:
w.outstanding--
}
}
} | go | {
"resource": ""
} |
q182728 | Gzip | test | func Gzip(h http.Handler, opts ...Option) http.Handler {
o := options{logger: handler.OutLogger()}
o.apply(opts)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
h.ServeHTTP(w, r)
return
}
wrapper := handler.NewResponseWrapper(w)
h.ServeHTTP(wrapper, r)
for k, v := range wrapper.Header() {
w.Header()[k] = v
}
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Content-Encoding", "gzip")
if w.Header().Get("Content-Type") == "" {
w.Header().Set("Content-Type", http.DetectContentType(wrapper.Body.Bytes()))
}
w.Header().Del("Content-Length")
if wrapper.Code != http.StatusOK {
w.WriteHeader(wrapper.Code)
}
gz := gzip.NewWriter(w)
gz.Flush()
if _, err := gz.Write(wrapper.Body.Bytes()); err != nil {
o.logger.Print("gzip handler: " + err.Error())
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
gz.Close()
})
} | go | {
"resource": ""
} |
q182729 | New | test | func New(uri string, user string, password string) InnkeeperClient {
return &IkClient{
URI: uri,
User: user,
Password: password,
}
} | go | {
"resource": ""
} |
q182730 | Error | test | func (r *Render) Error(status int, message ...string) {
r.WriteHeader(status)
if len(message) > 0 {
r.Write([]byte(message[0]))
}
} | go | {
"resource": ""
} |
q182731 | Renderer | test | func Renderer(options ...RenderOptions) Handler {
opt := prepareRenderOptions(options)
cs := prepareCharset(opt.Charset)
t := compile(opt)
return func(res http.ResponseWriter, req *http.Request, c Context) {
var tc *template.Template
if Env == Dev {
// recompile for easy development
tc = compile(opt)
} else {
// use a clone of the initial template
tc, _ = t.Clone()
}
//c.MapTo(&Render{res, req, tc, opt, cs, Data}, (*Render)(nil))
c.Map(&Render{res, req, tc, opt, cs, Data})
}
} | go | {
"resource": ""
} |
q182732 | NewClient | test | func NewClient(apiKey string, url string, client clientDoer) *PDClient {
return &PDClient{
APIKey: apiKey,
client: client,
URL: url,
}
} | go | {
"resource": ""
} |
q182733 | GetTask | test | func (s *PDClient) GetTask(taskID string) (task TaskResponse, res *http.Response, err error) {
req, _ := s.createRequest("GET", fmt.Sprintf("%s/v1/task/%s", s.URL, taskID), bytes.NewBufferString(``))
if res, err = s.client.Do(req); err == nil && res.StatusCode == http.StatusOK {
resBodyBytes, _ := ioutil.ReadAll(res.Body)
json.Unmarshal(resBodyBytes, &task)
} else {
lo.G.Error("client Do Error: ", err)
lo.G.Error("client Res: ", res)
err = ErrInvalidDispenserResponse
}
return
} | go | {
"resource": ""
} |
q182734 | WriteImageToHTTP | test | func WriteImageToHTTP(w http.ResponseWriter, img image.Image) error {
buffer := new(bytes.Buffer)
if err := png.Encode(buffer, img); err != nil {
return err
}
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Content-Length", strconv.Itoa(len(buffer.Bytes())))
if _, err := w.Write(buffer.Bytes()); err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |