_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q173700 | PeekFront | validation | func (list *LinkedList) PeekFront() (interface{}, bool) {
list.key.RLock()
defer list.key.RUnlock()
if list.first == nil {
return nil, false
}
return list.first.payload, true
} | go | {
"resource": ""
} |
q173701 | RemoveFront | validation | func (list *LinkedList) RemoveFront() (interface{}, bool) {
list.key.Lock()
defer list.key.Unlock()
if list.first == nil {
return nil, false
}
retval := list.first.payload
list.first = list.first.next
list.length--
if 0 == list.length {
list.last = nil
}
return retval, true
} | go | {
"resource": ""
} |
q173702 | RemoveBack | validation | func (list *LinkedList) RemoveBack() (interface{}, bool) {
list.key.Lock()
defer list.key.Unlock()
if list.last == nil {
return nil, false
}
retval := list.last.payload
list.length--
if list.length == 0 {
list.first = nil
} else {
node, _ := get(list.first, list.length-1)
node.next = nil
}
return r... | go | {
"resource": ""
} |
q173703 | Sort | validation | func (list *LinkedList) Sort(comparator Comparator) error {
list.key.Lock()
defer list.key.Unlock()
var err error
list.first, err = mergeSort(list.first, comparator)
if err != nil {
return err
}
list.last = findLast(list.first)
return err
} | go | {
"resource": ""
} |
q173704 | Sorta | validation | func (list *LinkedList) Sorta() error {
list.key.Lock()
defer list.key.Unlock()
var err error
list.first, err = mergeSort(list.first, func(a, b interface{}) (int, error) {
castA, ok := a.(string)
if !ok {
return 0, ErrUnexpectedType
}
castB, ok := b.(string)
if !ok {
return 0, ErrUnexpectedType
}... | go | {
"resource": ""
} |
q173705 | Sorti | validation | func (list *LinkedList) Sorti() (err error) {
list.key.Lock()
defer list.key.Unlock()
list.first, err = mergeSort(list.first, func(a, b interface{}) (int, error) {
castA, ok := a.(int)
if !ok {
return 0, ErrUnexpectedType
}
castB, ok := b.(int)
if !ok {
return 0, ErrUnexpectedType
}
return cast... | go | {
"resource": ""
} |
q173706 | String | validation | func (list *LinkedList) String() string {
list.key.RLock()
defer list.key.RUnlock()
builder := bytes.NewBufferString("[")
current := list.first
for i := 0; i < 15 && current != nil; i++ {
builder.WriteString(fmt.Sprintf("%v ", current.payload))
current = current.next
}
if current == nil || current.next == n... | go | {
"resource": ""
} |
q173707 | Swap | validation | func (list *LinkedList) Swap(x, y uint) error {
list.key.Lock()
defer list.key.Unlock()
var xNode, yNode *llNode
if temp, ok := get(list.first, x); ok {
xNode = temp
} else {
return fmt.Errorf("index out of bounds 'x', wanted less than %d got %d", list.length, x)
}
if temp, ok := get(list.first, y); ok {
... | go | {
"resource": ""
} |
q173708 | merge | validation | func merge(left, right *llNode, comparator Comparator) (first *llNode, err error) {
curLeft := left
curRight := right
var last *llNode
appendResults := func(updated *llNode) {
if last == nil {
last = updated
} else {
last.next = updated
last = last.next
}
if first == nil {
first = last
}
}
... | go | {
"resource": ""
} |
q173709 | split | validation | func split(head *llNode) (left, right *llNode) {
left = head
if head == nil || head.next == nil {
return
}
right = head
sprinter := head
prev := head
for sprinter != nil && sprinter.next != nil {
prev = right
right = right.next
sprinter = sprinter.next.next
}
prev.next = nil
return
} | go | {
"resource": ""
} |
q173710 | Add | validation | func (q *Queue) Add(entry interface{}) {
q.key.Lock()
defer q.key.Unlock()
if nil == q.underlyer {
q.underlyer = NewLinkedList()
}
q.underlyer.AddBack(entry)
} | go | {
"resource": ""
} |
q173711 | Enumerate | validation | func (q *Queue) Enumerate(cancel <-chan struct{}) Enumerator {
q.key.RLock()
defer q.key.RUnlock()
return q.underlyer.Enumerate(cancel)
} | go | {
"resource": ""
} |
q173712 | IsEmpty | validation | func (q *Queue) IsEmpty() bool {
q.key.RLock()
defer q.key.RUnlock()
return q.underlyer == nil || q.underlyer.IsEmpty()
} | go | {
"resource": ""
} |
q173713 | Length | validation | func (q *Queue) Length() uint {
q.key.RLock()
defer q.key.RUnlock()
if nil == q.underlyer {
return 0
}
return q.underlyer.length
} | go | {
"resource": ""
} |
q173714 | Next | validation | func (q *Queue) Next() (interface{}, bool) {
q.key.Lock()
defer q.key.Unlock()
if q.underlyer == nil {
return nil, false
}
return q.underlyer.RemoveFront()
} | go | {
"resource": ""
} |
q173715 | Peek | validation | func (q *Queue) Peek() (interface{}, bool) {
q.key.RLock()
defer q.key.RUnlock()
if q.underlyer == nil {
return nil, false
}
return q.underlyer.PeekFront()
} | go | {
"resource": ""
} |
q173716 | ToSlice | validation | func (q *Queue) ToSlice() []interface{} {
q.key.RLock()
defer q.key.RUnlock()
if q.underlyer == nil {
return []interface{}{}
}
return q.underlyer.ToSlice()
} | go | {
"resource": ""
} |
q173717 | EnableVirtualTerminalProcessing | validation | func EnableVirtualTerminalProcessing(fd int) error {
var st uint32
err := windows.GetConsoleMode(windows.Handle(fd), &st)
if err != nil {
return err
}
if st&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0 {
return windows.SetConsoleMode(windows.Handle(fd), st|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}
ret... | go | {
"resource": ""
} |
q173718 | unquote | validation | func unquote(input []byte, buf []byte) (unquoted []byte, remainder []byte) {
var (
errorIndicator = []byte("???")
)
if len(input) < 2 {
return errorIndicator, buf
}
quote := input[0]
input = input[1:]
if input[len(input)-1] == quote {
input = input[:len(input)-1]
}
index := bytes.IndexRune(input, '\\')
... | go | {
"resource": ""
} |
q173719 | countScalars | validation | func countScalars(input []interface{}) int {
for i := 0; i < len(input); i++ {
switch input[i].(type) {
case keyvalser:
return i
}
}
return len(input)
} | go | {
"resource": ""
} |
q173720 | IsTerminal | validation | func IsTerminal(writer io.Writer) bool {
if fd, ok := fileDescriptor(writer); ok {
return terminal.IsTerminal(fd)
}
return false
} | go | {
"resource": ""
} |
q173721 | Add | validation | func (l *List) Add(entries ...interface{}) {
l.key.Lock()
defer l.key.Unlock()
l.underlyer = append(l.underlyer, entries...)
} | go | {
"resource": ""
} |
q173722 | AddAt | validation | func (l *List) AddAt(pos uint, entries ...interface{}) {
l.key.Lock()
defer l.key.Unlock()
l.underlyer = append(l.underlyer[:pos], append(entries, l.underlyer[pos:]...)...)
} | go | {
"resource": ""
} |
q173723 | Enumerate | validation | func (l *List) Enumerate(cancel <-chan struct{}) Enumerator {
retval := make(chan interface{})
go func() {
l.key.RLock()
defer l.key.RUnlock()
defer close(retval)
for _, entry := range l.underlyer {
select {
case retval <- entry:
break
case <-cancel:
return
}
}
}()
return retval
} | go | {
"resource": ""
} |
q173724 | Get | validation | func (l *List) Get(pos uint) (interface{}, bool) {
l.key.RLock()
defer l.key.RUnlock()
if pos > uint(len(l.underlyer)) {
return nil, false
}
return l.underlyer[pos], true
} | go | {
"resource": ""
} |
q173725 | IsEmpty | validation | func (l *List) IsEmpty() bool {
l.key.RLock()
defer l.key.RUnlock()
return 0 == len(l.underlyer)
} | go | {
"resource": ""
} |
q173726 | Length | validation | func (l *List) Length() uint {
l.key.RLock()
defer l.key.RUnlock()
return uint(len(l.underlyer))
} | go | {
"resource": ""
} |
q173727 | Remove | validation | func (l *List) Remove(pos uint) (interface{}, bool) {
l.key.Lock()
defer l.key.Unlock()
if pos > uint(len(l.underlyer)) {
return nil, false
}
retval := l.underlyer[pos]
l.underlyer = append(l.underlyer[:pos], l.underlyer[pos+1:]...)
return retval, true
} | go | {
"resource": ""
} |
q173728 | Set | validation | func (l *List) Set(pos uint, val interface{}) bool {
l.key.Lock()
defer l.key.Unlock()
var retval bool
count := uint(len(l.underlyer))
if pos > count {
retval = false
} else {
l.underlyer[pos] = val
retval = true
}
return retval
} | go | {
"resource": ""
} |
q173729 | String | validation | func (l *List) String() string {
l.key.RLock()
defer l.key.RUnlock()
builder := bytes.NewBufferString("[")
for i, entry := range l.underlyer {
if i >= 15 {
builder.WriteString("... ")
break
}
builder.WriteString(fmt.Sprintf("%v ", entry))
}
builder.Truncate(builder.Len() - 1)
builder.WriteRune(']')... | go | {
"resource": ""
} |
q173730 | Swap | validation | func (l *List) Swap(x, y uint) bool {
l.key.Lock()
defer l.key.Unlock()
return l.swap(x, y)
} | go | {
"resource": ""
} |
q173731 | MarshalText | validation | func (l List) MarshalText() (text []byte, err error) {
var buf bytes.Buffer
l.writeToBuffer(&buf)
return buf.Bytes(), nil
} | go | {
"resource": ""
} |
q173732 | UnmarshalText | validation | func (l *List) UnmarshalText(text []byte) error {
m := parse.Bytes(text)
defer m.Release()
capacity := len(m.List)
if len(m.Text) == 0 {
capacity += 2
}
list := make(List, 0, capacity)
if len(m.Text) > 0 {
list = append(list, "msg", string(m.Text))
}
for _, v := range m.List {
list = append(list, string... | go | {
"resource": ""
} |
q173733 | repl | validation | func repl(match string, t time.Time) string {
if match == "%%" {
return "%"
}
formatFunc, ok := formats[match]
if ok {
return formatFunc(t)
}
return formatNanoForMatch(match, t)
} | go | {
"resource": ""
} |
q173734 | Format | validation | func Format(format string, t time.Time) string {
fn := func(match string) string {
return repl(match, t)
}
return fmtRe.ReplaceAllStringFunc(format, fn)
} | go | {
"resource": ""
} |
q173735 | logName | validation | func logName(logger, tag string, t time.Time) (name, link string) {
name = fmt.Sprintf("%s.%s.%s.log.%s.%s.%04d%02d%02d-%02d%02d%02d.%d",
program,
host,
userName,
logger,
tag,
t.Year(),
t.Month(),
t.Day(),
t.Hour(),
t.Minute(),
t.Second(),
pid)
return name, program + "." + tag
} | go | {
"resource": ""
} |
q173736 | Monotonic | validation | func Monotonic() time.Duration {
sec, nsec := monotime()
return time.Duration(sec*1000000000 + int64(nsec))
} | go | {
"resource": ""
} |
q173737 | set | validation | func (s *Severity) set(val Severity) {
atomic.StoreInt32((*int32)(s), int32(val))
} | go | {
"resource": ""
} |
q173738 | Set | validation | func (s *Severity) Set(value string) error {
var threshold Severity
// Is it a known name?
if v, ok := severityByName(value); ok {
threshold = v
} else {
v, err := strconv.Atoi(value)
if err != nil {
return err
}
threshold = Severity(v)
}
*s = threshold
return nil
} | go | {
"resource": ""
} |
q173739 | set | validation | func (l *Level) set(val Level) {
atomic.StoreInt32((*int32)(l), int32(val))
} | go | {
"resource": ""
} |
q173740 | match | validation | func (m *modulePat) match(file string) bool {
if m.literal {
return file == m.pattern
}
match, _ := filepath.Match(m.pattern, file)
return match
} | go | {
"resource": ""
} |
q173741 | match | validation | func (f *filepathPat) match(path string) bool {
return f.regexp.MatchString(path)
} | go | {
"resource": ""
} |
q173742 | match | validation | func (t *TraceLocation) match(file string, line int) bool {
if t.line != line {
return false
}
if i := strings.LastIndex(file, "/"); i >= 0 {
file = file[i+1:]
}
return t.file == file
} | go | {
"resource": ""
} |
q173743 | NewLogger | validation | func NewLogger(name string, skip int) *Log {
logging := &Log{stats: new(Stats)}
logging.setVState(0, nil, nil, false)
logging.skip = 2 + skip
logging.maxStackBufSize = 4096 * 1024
logging.name = name
// Default stderrThreshold is ERROR.
logging.stderrThreshold = ErrorLog
logging.setVState(0, nil, nil, false)
... | go | {
"resource": ""
} |
q173744 | SetLogDir | validation | func (l *Log) SetLogDir(logDir string) {
if logDir != "" {
l.mu.Lock()
defer l.mu.Unlock()
l.logDirs = append([]string{logDir}, l.logDirs...)
}
} | go | {
"resource": ""
} |
q173745 | SetLogToStderr | validation | func (l *Log) SetLogToStderr(f bool) {
l.mu.Lock()
defer l.mu.Unlock()
l.toStderr = f
} | go | {
"resource": ""
} |
q173746 | SetAlsoLogToStderr | validation | func (l *Log) SetAlsoLogToStderr(f bool) {
l.mu.Lock()
defer l.mu.Unlock()
l.alsoToStderr = f
} | go | {
"resource": ""
} |
q173747 | setVState | validation | func (l *Log) setVState(verbosity Level, modules []modulePat, filepaths []filepathPat, setFilter bool) {
// Turn verbosity off so V will not fire while we are in transition.
l.verbosity.set(0)
// Ditto for filter length.
atomic.StoreInt32(&l.filterLength, 0)
// Set the new filters and wipe the pc->Level map if th... | go | {
"resource": ""
} |
q173748 | getBuffer | validation | func (l *Log) getBuffer() *buffer {
l.freeListMu.Lock()
b := l.freeList
if b != nil {
l.freeList = b.next
}
l.freeListMu.Unlock()
if b == nil {
b = new(buffer)
} else {
b.next = nil
b.Reset()
}
return b
} | go | {
"resource": ""
} |
q173749 | putBuffer | validation | func (l *Log) putBuffer(b *buffer) {
if b.Len() >= 256 {
// Let big buffers die a natural death.
return
}
l.freeListMu.Lock()
b.next = l.freeList
l.freeList = b
l.freeListMu.Unlock()
} | go | {
"resource": ""
} |
q173750 | output | validation | func (l *Log) output(s Severity, buf *buffer, file string, line int) {
l.mu.Lock()
if l.traceLocation.isSet() {
if l.traceLocation.match(file, line) {
buf.Write(stacks(false, l.maxStackBufSize))
}
}
data := buf.Bytes()
if l.toStderr {
os.Stderr.Write(data)
} else {
if l.alsoToStderr || s >= l.stderrThr... | go | {
"resource": ""
} |
q173751 | timeoutFlush | validation | func timeoutFlush(l *Log, timeout time.Duration) {
done := make(chan bool, 1)
go func() {
l.lockAndFlushAll()
done <- true
}()
select {
case <-done:
case <-time.After(timeout):
fmt.Fprintln(os.Stderr, "glog: Flush took longer than", timeout)
}
} | go | {
"resource": ""
} |
q173752 | stacks | validation | func stacks(all bool, max int) []byte {
// We don't know how big the traces are, so grow a few times if they don't fit. Start large, though.
n := initialMaxStackBufSize
var trace []byte
for n <= max {
trace = make([]byte, n)
nbytes := runtime.Stack(trace, all)
if nbytes < len(trace) {
return trace[:nbytes]... | go | {
"resource": ""
} |
q173753 | exit | validation | func (l *Log) exit(err error) {
fmt.Fprintf(os.Stderr, "log: exiting because of error: %s\n", err)
// If logExitFunc is set, we do that instead of exiting.
if logExitFunc != nil {
logExitFunc(err)
return
}
l.flushAll()
os.Exit(2)
} | go | {
"resource": ""
} |
q173754 | rotateFile | validation | func (sb *syncBuffer) rotateFile(now time.Time) error {
if sb.file != nil {
sb.Flush()
sb.file.Close()
}
var err error
sb.file, _, err = sb.logger.create(severityName[sb.sev], now)
sb.nbytes = 0
if err != nil {
return err
}
sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)
// Write header.
var buf ... | go | {
"resource": ""
} |
q173755 | createFiles | validation | func (l *Log) createFiles(sev Severity) error {
now := time.Now()
// Files are created in decreasing severity order, so as soon as we find one
// has already been created, we can stop.
for s := sev; s >= InfoLog && l.file[s] == nil; s-- {
w, err := newFlushSyncWriter(l, s, now)
if err != nil {
return err
}... | go | {
"resource": ""
} |
q173756 | flushDaemon | validation | func (l *Log) flushDaemon() {
for _ = range time.NewTicker(flushInterval).C {
l.lockAndFlushAll()
}
} | go | {
"resource": ""
} |
q173757 | lockAndFlushAll | validation | func (l *Log) lockAndFlushAll() {
l.mu.Lock()
l.flushAll()
l.mu.Unlock()
} | go | {
"resource": ""
} |
q173758 | flushAll | validation | func (l *Log) flushAll() {
// Flush from fatal down, in case there's trouble flushing.
for s := FatalLog; s >= InfoLog; s-- {
file := l.file[s]
if file != nil {
file.Flush() // ignore error
file.Sync() // ignore error
}
}
} | go | {
"resource": ""
} |
q173759 | Add | validation | func (b *Bundle) Add(f func(context.Context) error) {
b.waitGroup.Add(1)
// Run the function in the background.
go func() {
defer b.waitGroup.Done()
err := f(b.context)
if err == nil {
return
}
// On first error, cancel the context and save the error.
b.errorOnce.Do(func() {
b.firstError = err
... | go | {
"resource": ""
} |
q173760 | Join | validation | func (b *Bundle) Join() error {
b.waitGroup.Wait()
// context.WithCancel requires that we arrange for this to be called
// eventually in order to avoid leaking resources. Since everything is done,
// to do so now is harmless.
b.cancel()
return b.firstError
} | go | {
"resource": ""
} |
q173761 | NewBundle | validation | func NewBundle(parent context.Context) *Bundle {
b := &Bundle{}
b.context, b.cancel = context.WithCancel(parent)
return b
} | go | {
"resource": ""
} |
q173762 | Expand | validation | func (tokens Tokens) Expand() (result Tokens, err error) {
var updated bool
for i := 0; i < len(tokens); i++ {
var start int
quote := Token{symbolToken, ":"}
if *tokens[i] != quote {
result = append(result, tokens[i])
} else {
updated = true
for start = i + 1; *tokens[start] == quote; start++ {
r... | go | {
"resource": ""
} |
q173763 | CacheFunc | validation | func CacheFunc(bodyHandler func(http.ResponseWriter, *http.Request), expiration time.Duration) http.HandlerFunc {
return Cache(http.HandlerFunc(bodyHandler), expiration).ServeHTTP
} | go | {
"resource": ""
} |
q173764 | CacheFasthttp | validation | func CacheFasthttp(bodyHandler fasthttp.RequestHandler, expiration time.Duration) *fhttp.Handler {
return fhttp.NewHandler(bodyHandler, expiration)
} | go | {
"resource": ""
} |
q173765 | CacheFasthttpFunc | validation | func CacheFasthttpFunc(bodyHandler fasthttp.RequestHandler, expiration time.Duration) fasthttp.RequestHandler {
return CacheFasthttp(bodyHandler, expiration).ServeHTTP
} | go | {
"resource": ""
} |
q173766 | ContentType | validation | func (r *Response) ContentType() string {
if r.contentType == "" {
r.contentType = "text/html; charset=utf-8"
}
return r.contentType
} | go | {
"resource": ""
} |
q173767 | ServeHTTP | validation | func (s *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// println("Request to the remote service has been established")
key := getURLParam(r, cfg.QueryCacheKey)
if key == "" {
// println("return because key was empty")
w.WriteHeader(cfg.FailStatus)
return
}
// we always need the Entry, so get... | go | {
"resource": ""
} |
q173768 | New | validation | func New(addr string, store Store) *http.Server {
if store == nil {
store = NewMemoryStore()
}
h := &Handler{store: store}
return &http.Server{
Addr: addr,
Handler: h,
}
} | go | {
"resource": ""
} |
q173769 | AcquireResponseRecorder | validation | func AcquireResponseRecorder(underline http.ResponseWriter) *ResponseRecorder {
v := rpool.Get()
var res *ResponseRecorder
if v != nil {
res = v.(*ResponseRecorder)
} else {
res = &ResponseRecorder{}
}
res.underline = underline
return res
} | go | {
"resource": ""
} |
q173770 | ReleaseResponseRecorder | validation | func ReleaseResponseRecorder(res *ResponseRecorder) {
res.underline = nil
res.statusCode = 0
res.chunks = res.chunks[0:0]
rpool.Put(res)
} | go | {
"resource": ""
} |
q173771 | Claim | validation | func (v *validatorRule) Claim(r *http.Request) bool {
// check for pre-cache validators, if at least one of them return false
// for this specific request, then skip the whole cache
for _, shouldProcess := range v.preValidators {
if !shouldProcess(r) {
return false
}
}
return true
} | go | {
"resource": ""
} |
q173772 | Rule | validation | func (h *Handler) Rule(r rule.Rule) *Handler {
if r == nil {
// if nothing passed then use the allow-everyting rule
r = rule.Satisfied()
}
h.rule = r
return h
} | go | {
"resource": ""
} |
q173773 | Reset | validation | func (e *Entry) Reset(statusCode int, contentType string,
body []byte, lifeChanger LifeChanger) {
if e.response == nil {
e.response = &Response{}
}
if statusCode > 0 {
e.response.statusCode = statusCode
}
if contentType != "" {
e.response.contentType = contentType
}
e.response.body = body
// check if ... | go | {
"resource": ""
} |
q173774 | NoCache | validation | func NoCache(reqCtx *fasthttp.RequestCtx) {
reqCtx.Response.Header.Set(cfg.NoCacheHeader, "true")
} | go | {
"resource": ""
} |
q173775 | clientOAuth | validation | func clientOAuth(tokens *oauthTokens) *clientOAuthAuthentication {
a := clientOAuthAuthentication{
Tokens: tokens,
BaseUrl: config.BaseUrl,
Client: http.Client{
Transport: &http.Transport{
Dial: dialTimeout,
},
},
}
return &a
} | go | {
"resource": ""
} |
q173776 | authenticate | validation | func (a clientOAuthAuthentication) authenticate(req *http.Request, endpoint string, params []byte) error {
// Ensure tokens havent expired
if time.Now().UTC().Unix() > a.Tokens.ExpireTime {
return errors.New("The OAuth tokens are expired. Use refreshTokens to refresh them")
}
req.Header.Set("Authorization", "Bear... | go | {
"resource": ""
} |
q173777 | apiKeyAuth | validation | func apiKeyAuth(key string, secret string) *apiKeyAuthentication {
a := apiKeyAuthentication{
Key: key,
Secret: secret,
BaseUrl: config.BaseUrl,
Client: http.Client{
Transport: &http.Transport{
Dial: dialTimeout,
},
},
}
return &a
} | go | {
"resource": ""
} |
q173778 | authenticate | validation | func (a apiKeyAuthentication) authenticate(req *http.Request, endpoint string, params []byte) error {
nonce := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
message := nonce + endpoint + string(params) //As per Coinbase Documentation
req.Header.Set("ACCESS_KEY", a.Key)
h := hmac.New(sha256.New, []byte(a.Sec... | go | {
"resource": ""
} |
q173779 | serviceOAuth | validation | func serviceOAuth(certFilePath string) (*serviceOAuthAuthentication, error) {
// First we read the cert
certs := x509.NewCertPool()
pemData, err := ioutil.ReadFile(certFilePath)
if err != nil {
return nil, err
}
certs.AppendCertsFromPEM(pemData)
mTLSConfig := &tls.Config{
RootCAs: certs, //Add the cert as a ... | go | {
"resource": ""
} |
q173780 | authenticate | validation | func (a serviceOAuthAuthentication) authenticate(req *http.Request, endpoint string, params []byte) error {
return nil // No additional headers needed for service OAuth requests
} | go | {
"resource": ""
} |
q173781 | OAuthService | validation | func OAuthService(clientId string, clientSecret string, redirectUri string) (*OAuth, error) {
certFilePath := basePath + "/ca-coinbase.crt"
serviceAuth, err := serviceOAuth(certFilePath)
if err != nil {
return nil, err
}
o := OAuth{
ClientId: clientId,
ClientSecret: clientSecret,
RedirectUri: redirect... | go | {
"resource": ""
} |
q173782 | CreateAuthorizeUrl | validation | func (o OAuth) CreateAuthorizeUrl(scope []string) string {
Url, _ := url.Parse("https://coinbase.com")
Url.Path += "/oauth/authorize"
parameters := url.Values{}
parameters.Add("response_type", "code")
parameters.Add("client_id", o.ClientId)
parameters.Add("redirect_uri", o.RedirectUri)
parameters.Add("scope", s... | go | {
"resource": ""
} |
q173783 | RefreshTokens | validation | func (o OAuth) RefreshTokens(oldTokens map[string]interface{}) (*oauthTokens, error) {
refresh_token := oldTokens["refresh_token"].(string)
return o.GetTokens(refresh_token, "refresh_token")
} | go | {
"resource": ""
} |
q173784 | NewTokens | validation | func (o OAuth) NewTokens(code string) (*oauthTokens, error) {
return o.GetTokens(code, "authorization_code")
} | go | {
"resource": ""
} |
q173785 | NewTokensFromRequest | validation | func (o OAuth) NewTokensFromRequest(req *http.Request) (*oauthTokens, error) {
query := req.URL.Query()
code := query.Get("code")
return o.GetTokens(code, "authorization_code")
} | go | {
"resource": ""
} |
q173786 | Request | validation | func (r rpc) Request(method string, endpoint string, params interface{}, holder interface{}) error {
jsonParams, err := json.Marshal(params)
if err != nil {
return err
}
request, err := r.createRequest(method, endpoint, jsonParams)
if err != nil {
return err
}
var data []byte
if r.mock == true { // Mock ... | go | {
"resource": ""
} |
q173787 | createRequest | validation | func (r rpc) createRequest(method string, endpoint string, params []byte) (*http.Request, error) {
endpoint = r.auth.getBaseUrl() + endpoint //BaseUrl depends on Auth type used
req, err := http.NewRequest(method, endpoint, bytes.NewBuffer(params))
if err != nil {
return nil, err
}
// Authenticate the request
... | go | {
"resource": ""
} |
q173788 | executeRequest | validation | func (r rpc) executeRequest(req *http.Request) ([]byte, error) {
resp, err := r.auth.getClient().Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
bytes := buf.Bytes()
if resp.StatusCode != 200 {
if len(bytes) == 0 { // Log response body for d... | go | {
"resource": ""
} |
q173789 | simulateRequest | validation | func (r rpc) simulateRequest(endpoint string, method string) ([]byte, error) {
// Test files conform to replacing '/' in endpoint with '_'
fileName := strings.Replace(endpoint, "/", "_", -1)
// file names also have method type prepended to ensure uniqueness
filePath := basePath + "/test_data/" + method + "_" + file... | go | {
"resource": ""
} |
q173790 | ApiKeyClient | validation | func ApiKeyClient(key string, secret string) Client {
c := Client{
rpc: rpc{
auth: apiKeyAuth(key, secret),
mock: false,
},
}
return c
} | go | {
"resource": ""
} |
q173791 | OAuthClient | validation | func OAuthClient(tokens *oauthTokens) Client {
c := Client{
rpc: rpc{
auth: clientOAuth(tokens),
mock: false,
},
}
return c
} | go | {
"resource": ""
} |
q173792 | Get | validation | func (c Client) Get(path string, params interface{}, holder interface{}) error {
return c.rpc.Request("GET", path, params, &holder)
} | go | {
"resource": ""
} |
q173793 | GetBalance | validation | func (c Client) GetBalance() (float64, error) {
balance := map[string]string{}
if err := c.Get("account/balance", nil, &balance); err != nil {
return 0.0, err
}
balanceFloat, err := strconv.ParseFloat(balance["amount"], 64)
if err != nil {
return 0, err
}
return balanceFloat, nil
} | go | {
"resource": ""
} |
q173794 | GetAllAddresses | validation | func (c Client) GetAllAddresses(params *AddressesParams) (*addresses, error) {
holder := addressesHolder{}
if err := c.Get("addresses", params, &holder); err != nil {
return nil, err
}
addresses := addresses{
paginationStats: holder.paginationStats,
}
// Remove one layer of nesting
for _, addr := range holde... | go | {
"resource": ""
} |
q173795 | GenerateReceiveAddress | validation | func (c Client) GenerateReceiveAddress(params *AddressParams) (string, error) {
holder := map[string]interface{}{}
if err := c.Post("account/generate_receive_address", params, &holder); err != nil {
return "", err
}
return holder["address"].(string), nil
} | go | {
"resource": ""
} |
q173796 | SendMoney | validation | func (c Client) SendMoney(params *TransactionParams) (*transactionConfirmation, error) {
return c.transactionRequest("POST", "send_money", params)
} | go | {
"resource": ""
} |
q173797 | RequestMoney | validation | func (c Client) RequestMoney(params *TransactionParams) (*transactionConfirmation, error) {
return c.transactionRequest("POST", "request_money", params)
} | go | {
"resource": ""
} |
q173798 | ResendRequest | validation | func (c Client) ResendRequest(id string) (bool, error) {
holder := map[string]interface{}{}
if err := c.Put("transactions/"+id+"/resend_request", nil, &holder); err != nil {
return false, err
}
if holder["success"].(bool) {
return true, nil
}
return false, nil
} | go | {
"resource": ""
} |
q173799 | CancelRequest | validation | func (c Client) CancelRequest(id string) (bool, error) {
holder := map[string]interface{}{}
if err := c.Delete("transactions/"+id+"/cancel_request", nil, &holder); err != nil {
return false, err
}
if holder["success"].(bool) {
return true, nil
}
return false, nil
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.