text stringlengths 11 4.05M |
|---|
package parsing
import (
"fmt"
"strings"
"github.com/s2gatev/sqlmorph/ast"
)
// wrongTokenPanic causes a panic because of an unexpected token.
func wrongTokenPanic(message string, value string) {
if value != "" {
message += fmt.Sprintf(" Found %s.", value)
}
panic(message)
}
// parseField parses field extra... |
// chaincode_insurance project main.go
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
)
type InsuranceChaincode struct {
}
type Policy struct {
PolicyNo string //保单号码
PolicyType string //险种
Startdate string //保险生效时间
Enddate string //保险失效... |
package escrow
import (
"context"
"encoding/json"
"errors"
"math"
"time"
cosmosTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/gookit/gcli/v3"
"github.com/ovrclk/akash/x/deployment/client/cli"
deploymentTypes "github.com/ovrclk/akash/x/deployment/types"
marketTypes "github.com/ovrclk/akash/x/market/t... |
package main
import (
"fmt"
)
func Handler(x int, y int) int {
return x * (2 + y)
}
func main() {
fmt.Print("input x: ")
var x int
fmt.Scanf("%d", &x)
fmt.Print("input y: ")
var y int
fmt.Scanf("%d", &y)
result := Handler(x, y)
fmt.Println(fmt.Sprintf("result: %d", result))
}
|
package app
import (
"net/http"
"encoding/json"
"strconv"
"portal/util"
"portal/model"
"portal/service"
"github.com/gin-gonic/gin"
)
// Create app
func CreateApp(c *gin.Context) {
type App struct {
Name string `json:"name,omitempty"`
}
var jsonBody App
err := c.BindJSON(&jsonBody)
if err != nil {
uti... |
package error
import "fmt"
// DataConflictError indicates conflicting data for a resource
type DataConflictError struct {
Resource string
Field string
}
func (dce *DataConflictError) Error() string {
return fmt.Sprintf("Conflicting data for %s field in %s resource", dce.Field, dce.Resource)
}
|
/**
* @Author: 人从众[ckhero]
* @Date: 2020/8/26 6:56 下午
* @Desc: a
*/
package go_way
type Ints []int
func(i Ints) Iterator() <-chan int {
c := make(chan int)
go func() {
for _, v := range i {
c <- v
}
close(c)
}()
return c
}
|
package goSolution
func beautifulArray(n int) []int {
if n == 1 {
return []int{1}
}
left := beautifulArray((n + 1) >> 1)
right := beautifulArray(n >> 1)
for i, v := range left {
left[i] = (v << 1) - 1
}
for i, v := range right {
right[i] = v << 1
}
return append(left, right...)
}
|
package goutils
import (
"encoding/json"
"fmt"
"os"
)
// SaveJSON saves the given data to json
func SaveJSON(data interface{}, outputname string) {
file, err := os.Create(outputname)
defer file.Close()
if err != nil {
fmt.Println(err)
return
}
err = json.NewEncoder(file).Encode(data)
if err != nil {
fm... |
// This file exposes volume plugin related contracts.
// Hence, any specific volume plugin implementor will
// implement the logic that aligns to the contracts
// exposed here.
// Some of the plugin based interfaces delegate to
// volume based interfaces to do the actual work.
package volume
import (
"fmt"
"io"
"os... |
package log
import (
"github.com/sirupsen/logrus"
"io"
"reflect"
"time"
)
var (
// global state for convenient way to switch all services together
loggerLevel = TraceLevel
logger = logrus.New()
)
const (
// PanicLevel level, highest level of severity. Logs and then calls panic with the
// message passe... |
package main
import (
"fmt"
"time"
"sync"
"sync/atomic"
)
var countConcurrency int32 = 0
var wg2 sync.WaitGroup
func main(){
wg2.Add(3)
go concurrencyTeste("Thread1 ")
go concurrencyTeste("Thread2 ")
go concurrencyTeste("Thread3 ")
wg2.Wait()
}
func concurrencyTeste(threadName string){
for i:=0;i<100;i++... |
package log
import (
"fmt"
"log"
"os"
"time"
"path/filepath"
"runtime"
"github.com/natefinch/lumberjack"
)
var (
// ErrorLog logger with custom formatting, written to stdOut
ErrorLog *log.Logger
// FatalLog logger with custom formatting, written to stdOut
FatalLog *log.Logger
// InfoLog logger with cust... |
package basic
import (
"fmt"
)
func go1() {
data := []string{"one", "two", "three"}
for _, v := range data {
go func() {
fmt.Println(v)
}()
}
//time.Sleep(3 * time.Second)
//goroutines print: three, three, three
}
func go2() {
data := []string{"one", "two", "three"}
for _, v := range data {
vcopy :=... |
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, ... |
package sort
import (
"sort"
"testing"
"github.com/seifer/go-dsa/sort/heapsort"
"github.com/seifer/go-dsa/sort/insertionsort"
"github.com/seifer/go-dsa/sort/mergesort"
"github.com/seifer/go-dsa/sort/quicksort"
"github.com/seifer/go-dsa/sort/selectionsort"
"github.com/seifer/go-dsa/sort/shellsort"
"github.com... |
package api
import (
"fmt"
"github.com/yaziedda/iser/app/common"
"github.com/yaziedda/iser/app/user"
"math/rand"
"net/http"
"strconv"
"time"
)
func UserLoginHandler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
common.CheckError(err)
email := r.PostFormValue("user_email")
password := r.Pos... |
package sound
/*
#cgo pkg-config: alsa
#include <stdbool.h>
#include <stdint.h>
#include <alsa/asoundlib.h>
#include "estr.h"
static snd_pcm_t* openDevice(const char *deviceName, unsigned int rate, EStr* estr) {
int err = 0;
snd_pcm_hw_params_t* params = NULL;
snd_pcm_t* handle = NULL;
if ((err = snd_pcm_open... |
package main
import (
"io"
"log"
"net/http"
)
func main() {
// Hello world, the web server
helloHandler := func(w http.ResponseWriter, req *http.Request) {
if req.ParseForm() == nil && req.Form.Get("secret") == "secret" {
io.WriteString(w, `{
"ttl": 3600,
"identity": "username",
"identity_url": ... |
package superhero
import (
"context"
"database/sql"
"errors"
"github.com/go-kit/kit/log/level"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
"google.golang.org/grpc/codes"
pb "github.com/jace-ys/super-smash-heroes/services/superhero/api/superhero"
)
func (s *SuperheroService) List(ctx context.Context, req *... |
// Copyright 2016-2021 terraform-provider-sakuracloud authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required b... |
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"gopkg.in/alecthomas/kingpin.v1"
"log"
"os"
"sort"
"strconv"
)
var (
app = kingpin.New("dead-letter-requeue", "Requeue messages from a SQS dead-letter queue to the a... |
package handler
import (
"context"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jinmukeji/jiujiantang-services/jinmuid/mysqldb"
proto "github.com/jinmukeji/proto/v3/gen/micro/idl/partner/xima/user/v1"
)
// 邮箱验证超时时间
const (
EmailValificationExpiration = time.Minute * 10
ResetPassword ... |
package main
import (
pb "github.com/micro/services/db/proto"
admin "github.com/micro/services/pkg/service/proto"
"github.com/micro/services/pkg/tracing"
"github.com/micro/services/db/handler"
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/logger"
"database/sql"
"github.com/micro/mi... |
package ttlib
import (
"fmt"
"github.com/johnnylee/util"
"path/filepath"
"sync"
"time"
)
// PwdHandler provides an interface for requesting user's passwords.
type PwdHandler struct {
mutex sync.RWMutex
hash map[string][]byte
baseDir string
}
func NewPwdHandler(baseDir string) *PwdHandler {
ph := new(Pw... |
package dht
import (
"bytes"
"net"
"sync"
"time"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/google/gopacket/routing"
netroute "github.com/libp2p/go-netroute"
ma "github.com/multiformats/go-multiaddr"
manet "github... |
//author xinbing
//time 2018/9/4 17:17
package db
import (
"github.com/go-redis/redis"
"github.com/sirupsen/logrus"
"time"
)
var RedisClient *redis.Client
func InitRedis(redisConfig *RedisConfig) {
RedisClient = redis.NewClient(&redis.Options{
Addr: redisConfig.RedisAddr,
Password: redisConfig.RedisPwd, ... |
package fakes
import (
"io/ioutil"
"net/http"
"strings"
)
type FakeHTTPClient struct {
PostInputs []postInput
postOutputs []postOutput
GetInputs []getInput
getOutputs []getOutput
}
type postInput struct {
Payload []byte
Endpoint string
}
type postOutput struct {
response *http.Response
err error... |
package piper
import (
"context"
"fmt"
"sync"
)
// Pipeline is an object used for chaining multiple Processes together sequentially
type Pipeline struct {
// required
name string // Name of the pipeline
processes []*Process // Processes that make up the pipeline arranged in order that they should be ru... |
package main
import (
"github.com/Depado/ginprom"
"github.com/gin-gonic/contrib/cors"
"github.com/gin-gonic/gin"
"github.com/janwiemers/up/handler"
"github.com/janwiemers/up/helper"
"github.com/janwiemers/up/models"
"github.com/janwiemers/up/monitors"
"github.com/janwiemers/up/websockets"
log "github.com/siru... |
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to i... |
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... |
// A goroutine is a lightweight thread managed by the Go runtime.
// The evaluation of f, x, y, and z happens in the current goroutine
// and the execution of f happens in the new goroutine.
// Goroutines run in the same address space,
// so access to shared memory must be synchronized.
// The sync package provides use... |
// Copyright 2023 beego-dev
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writin... |
package main
import (
"fmt"
)
func main() {
capitals := make(map[string]string, 3)
capitals["Japan"] = "Tokyo"
capitals["US"] = "Washington D. C."
capitals["China"] = "Beijing"
for k, v := range capitals {
fmt.Printf("%v: %v\n", k, v)
}
// キーの存在確認
capital, ok := capitals["UK"]
if ok {
fmt.Println("re... |
package jwt
import (
"backend/utils/common"
"backend/utils/logging"
"backend/utils/response"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func JWT() gin.HandlerFunc {
return func(c *gin.Context) {
var code int
var data interface{}
var token string
code = response.SUCCESS
token = c.Query("token")
... |
package assertion
// Interface for Stubs
type Stuber interface {
CallCount(string) CallCount
Register(string)
}
// Struct for containin the function call count data
type CallCount struct {
funcName string
callCount int
}
func NewStub() *Stub {
callCount := make([]CallCount, 0)
stub := Stub{callCount}
return... |
package main
import (
"code.huawei.com/server/serve"
)
func main() {
serve.Serve()
}
|
package services
import (
"goChat/Server/db"
"goChat/Server/models"
"goChat/Server/utils"
"goChat/Server/viewModels"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
// MessageService - MessageService
type MessageService struct {
repo db.IMessageRepository
}
// NewMessageService - Creates new instance of Mes... |
// Copyright 2017 Yahoo Holdings Inc.
// Licensed under the terms of the 3-Clause BSD License.
package provider
import (
"fmt"
"strings"
"k8s.io/api/extensions/v1beta1"
"k8s.io/client-go/tools/cache"
)
var (
helper *Helper
)
// Helper class that provides common validation funcs and a handle to
// ingress claim... |
// threadPool_test
package threadPool
import (
"fmt"
"github.com/ziyouchutuwenwu/objective-go/dataFoundation/dataType/object"
"github.com/ziyouchutuwenwu/objective-go/thread/msgThread"
"testing"
"time"
)
var thread1 *msgThread.Thread
var thread2 *msgThread.Thread
type Test struct{}
func (test *Test) MyThreadCa... |
package functions
import (
"github.com/webmachinedev/src/types"
)
func SearchFunctions(client types.Person, text string) {
}
|
package main
import "fmt"
func main() {
bd := 1998
for bd < 2022 {
fmt.Println(bd)
bd++
}
}
|
package semt
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document01400101 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:semt.014.001.01 Document"`
Message *IntraPositionMovementStatusAdviceV01 `xml:"IntraPosMvmntStsAdvc"`
}
... |
package core
import (
"testing"
)
func Test_NewHashmap_IsHashmap_IsEmptyHashmap(t *testing.T) {
hashmap := NewHashmap()
if !hashmap.IsHashmap() {
t.Error("NewHashmap() failed.")
}
if !hashmap.IsEmptyHashmap() {
t.Error("NewHashmap() failed.")
}
}
func Test_NewHashmapFromSequence_With_Even_Values(t *testi... |
package main
import (
"net/http"
"log"
"fmt"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
log.Print("req [%v]", *r)
fmt.Fprintln(w, "hello world")
}
// 入口函数
func main() {
http.Handle("/", sayHello)
err := http.ListenAndServe(":7000", nil)
if err != nil {
log.Fatal("ListenAndServe error",err)
... |
package constant
const Version = "v0.16.5"
|
package Utils
import (
"fmt"
"net"
"strings"
)
// 获取本地对外IP
func GetOutboundIP()(ip string, err error) {
// 使用udp的方式拨号
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
fmt.Printf("get ip failed, err: %s, \n", err)
return
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
fmt.Pri... |
package etcdv3
import (
"Common/logger"
"context"
"errors"
"fmt"
"strings"
etcd3 "github.com/coreos/etcd/clientv3"
"google.golang.org/grpc/naming"
)
// resolver is the implementaion of grpc.naming.Resolver
type resolver struct {
serviceName string // service name to resolve
}
// NewResolver return resolver ... |
package entity
import (
"time"
"github.com/fatih/structs"
)
type Token struct {
Id int64
Chain string // 主链
Token string // 币种符号
Contract string // 代币合约地址
Precision int64 // 币种精度
Protocol s... |
package problem0594
func findLHS(nums []int) int {
dict := map[int]int{}
for _, num := range nums {
dict[num]++
}
max := 0
for key, count := range dict {
if dict[key-1] == 0 {
continue
}
if count+dict[key-1] > max {
max = count + dict[key-1]
}
}
return max
}
|
package sort
/*
Notes:
简单概括,相邻两元素作比较,遍历区间逐步缩小。
效率低下。
稳定排序。
*/
// time complexity: O(N) ~ O(N^2)
func bubbleSort(nums []int) {
var swapped bool
for i := len(nums) - 1; i > 0; i-- {
swapped = false
for j := 0; j < i; j++ {
if nums[j] > nums[j+1] {
nums[j], nums[j+1] = nums[j+1], nums[j]
swapped = true... |
package models
type User struct {
Base
Name string `json:"name"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
Task []Task `gorm:"foreignKey:UserId"`
Category []Category `gorm:"foreignKey:UserId"`
}
|
package problem0090
import "sort"
func subsetsWithDup(nums []int) [][]int {
sort.Ints(nums)
result := [][]int{}
visited := make([]bool, len(nums))
subset := []int{}
for i := 0; i <= len(nums); i++ {
backtrack(nums, visited, subset, 0, i, &result)
}
return result
}
func backtrack(nums []int, visited []bool, ... |
package main
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
pb "github.com/vlasove/Lec12/shippyvessel/proto/vessel"
)
//Модельный файл
//Repository ...
type repository interface {
FindAvailable(ctx context.Context, spec *Specification) (*Vessel, error)
Create(ctx co... |
package command
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/quilt/quilt/api"
clientMock "github.com/quilt/quilt/api/client/mocks"
"github.com/quilt/quilt/db"
)
func TestPsFlags(t *testing.T) {
t.Parallel()
expHost := "IP"
cmd :=... |
package v1alpha1
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
type DeviceSpec struct{}
type DeviceStatus struct {
// Registered denotes wether or not this device is considered as
// being registered or not.
Registered bool `json:"registered"`
}
// +kubebuilder:object:root=true
type Device struct {
metav... |
package metadata
import (
"encoding/gob"
"fmt"
"io"
"os"
"github.com/golang/snappy"
"github.com/root-gg/plik/server/common"
)
type metadataType int
const (
metadataTypeUpload metadataType = iota
metadataTypeFile
metadataTypeUser
metadataTypeToken
metadataTypeSetting
)
type object struct {
Type metad... |
package model
type FilterTypeResponse struct {
// The type of the filter
Type FilterType `json:"type,omitempty"`
}
|
// This file was generated for SObject Order, API Version v43.0 at 2018-07-30 03:47:56.801421065 -0400 EDT m=+43.145646441
package sobjects
import (
"fmt"
"strings"
)
type Order struct {
BaseSObject
AccountId string `force:",omitempty"`
ActivatedById string `force:",omitempty"`
Acti... |
package cmd
import (
"fmt"
"github.com/go-openapi/spec"
"github.com/spf13/cobra"
)
func filterCmd(cmd *cobra.Command, args []string) error {
var filters filters
err := addEndpoints(cmd, &filters)
if err != nil {
return err
}
err = addPrefixEndpoints(cmd, &filters)
if err != nil {
return err
}
err =... |
package util
import (
"github.com/twinj/uuid"
)
// UUID ...
func UUID() string {
return uuid.NewV4().String()
}
|
package main
import ("fmt")
func main() {
a := make(map[string]int)
a["id"] = 11
a["ids"] = 111
fmt.Println(a)
delete(a, "ids")
fmt.Println(a)
_, is := a["id"]
fmt.Println(is)
} |
package golinal
import (
"errors";
"math";
"fmt";
"github.com/gonum/Matrix/mat64";
)
// Matrix Struct Definition
//
type Matrix struct {
numRows, numCols int
elems [][]float64
}
// brief: Parameterized constructor that takes slice
// of slices of floats
//
// details: Allows us to create a Matrix with only
/... |
package cointop
import (
"math"
"github.com/jroimartin/gocui"
apt "github.com/miguelmota/cointop/pkg/api/types"
"github.com/miguelmota/cointop/pkg/pad"
"github.com/miguelmota/cointop/pkg/table"
)
func (ct *Cointop) layout(g *gocui.Gui) error {
maxX, maxY := ct.Size()
chartHeight := 10
topOffset := 0
if v, ... |
package moxxiConf
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strconv"
"text/template"
)
func CreateMux(handlers []HandlerConfig, l *log.Logger) *http.ServeMux {
mux := http.NewServeMux()
for _, handler := range handlers {
switch handler.handlerType {
case "json":
mux.HandleFunc(handler.hand... |
// Package common implements common things for Oasis Core Ledger.
package common
import (
"runtime"
"strings"
)
var (
// SoftwareVersion represents the Oasis Core Ledger's version and should be
// set by the linker.
SoftwareVersion = "0.0-unset"
// ToolchainVersion is the version of the Go compiler/standard li... |
package encodemain
import (
"fmt"
"gostudy/src/mystudy/encode/easyjson1"
"time"
)
func JsonEasyEncode() {
fmt.Println("<-------------------- JsonEasyEncode begin ------------------------->")
s := easyjson1.Student{
Id: 11,
Name: "qq",
School: easyjson1.School{
Name: "CUMT",
Addr: "xz",
},
Bi... |
package common
import (
"flag"
"os"
"path/filepath"
)
const (
MaxConcurrentDownloadTasksNumber = 16
)
var (
MP3DownloadDir string
MP3DownloadBr int
MP3ConcurrentDownloadTasksNumber int
)
func init() {
homedir, err := os.UserHomeDir()
if err != nil {
homedir = "."
}
... |
/*
Copyright (c) 2017 Simon Schmidt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, s... |
package main
import (
"fmt"
"math"
"math/rand"
"time"
log "github.com/sirupsen/logrus"
)
const NOT_IN_PROCESS = 1
const IN_PROCESS = 2
const PROCESSED = 3
const EVENT_GAME = "game"
const EVENT_GAME_START = "game_start"
const EVENT_GAME_OVER = "game_over"
const EVENT_DAY = "day"
const EVENT_NIGHT = "night"
cons... |
package main
import "fmt"
func main() {
/*
basic "if" statement
*/
num := 10
if num%2 == 0 {
fmt.Println("The number is even")
return
}
fmt.Println("The number is odd")
/*
basic "if-else" statement
*/
num = 11
if num%2 == 0 {
fmt.Println("The number is even")
} else { //... |
package problem0300
func lengthOfLIS(nums []int) int {
if len(nums) == 0 {
return 0
}
if len(nums) == 1 {
return 1
}
dp := make([]int, len(nums))
dp[0] = 1
ret := 1
for i := 1; i < len(nums); i++ {
dp[i] = 1
tmp := 1
for j := 0; j < i; j++ {
if nums[i] > nums[j] {
tmp = max(tmp, dp[j]+1)
}
... |
package processor
import "mdcdntools/common"
type Processor interface {
Execute(config common.ArgsConfig) (bool, error)
}
|
package main
import "fmt"
type Animal struct {
Name string
}
type Dog struct {
Animal
}
type Sleep interface {
Sleep()
}
func (a *Animal) Eat() {
}
func (a *Animal) Sleep() {
fmt.Println(a.Name, "sleep")
}
func (a *Animal) Run() {
fmt.Println(a.Name, "running")
}
func main() {
//var sleep Sleep
//
//d:=... |
package controller
import (
"github.com/golang/glog"
clientSet "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
"github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions"
"github.com/api7/ingress-controller/log"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/informers"... |
package app
import (
"encoding/json"
"net/http"
"net/url"
"strconv"
"github.com/gorilla/mux"
"github.com/interview304/interview/server/models"
)
func (app *App) DeleteInterviewHandler(writer http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
idStr := vars["id"]
interviewID, err := strco... |
package zendesk
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
client "github.com/nukosuke/go-zendesk/zendesk"
)
// https://developer.zendesk.com/rest_api/docs/core/ticket_fields
func resourceZendeskTicketField() *schema.Resource {
return &schema... |
/*
Connects to the Binance WebSocket and write orderBook to redis
*/
package main
// import "github.com/davecgh/go-spew/spew"
import "time"
import (
"encoding/json"
"fmt"
"github.com/go-redis/redis"
"github.com/gorilla/websocket"
"github.com/pdepip/go-binance/binance"
"log"
"os"
"strconv"
"strings"
"sync"... |
package main
import "fmt"
//结构体是值类型
type person struct {
name string
age int
gender bool
hobby []string
}
func f1(x person) {
x.gender = false
}
func f2(y *person) {
(*y).gender = false
}
func main() {
var p person
p.name = "老王"
p.gender = true
f1(p)
fmt.Println(p)
f2(&p)
fmt.Println(p)
var p2... |
package cli
import "github.com/spf13/cobra"
func newServerCommand(cli *CLI) *cobra.Command {
cmd := &cobra.Command{
Use: "server",
Short: "Manage servers",
Args: cobra.NoArgs,
TraverseChildren: true,
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
... |
package main
import(
"crypto/md5"
"fmt"
"io"
"log"
"os"
)
// Function main opens a txt file and checks if the file exists if not logs an errors.
// Creates a new md5 hash and copies the hash to the file and logs any errors
// Prints the hash sum and closes the file
func main() {
file, err := os.Open("fil... |
/**
* menu_vo
* @author liuzhen
* @Description
* @version 1.0.0 2021/3/9 21:34
*/
package module
// 路由菜单
type Menu struct {
// 名称
Label string `json:"label"`
// 路径
Path string `json:"path"`
// 名称
Name string `json:"name"`
// 图标
Icon string `json:"icon"`
// 子路由
Children []Menu `json:"children"`
}
|
package xmpp
import (
"encoding/xml"
"fmt"
)
type Element struct {
StartElement xml.StartElement
EndElement xml.EndElement
CharData string
Comment xml.Comment
ProcInst xml.ProcInst
Directive xml.Directive
Children []*Element
Parent *Element
}
func NewElement(parent *Element) *El... |
package routetable
import (
"context"
"fmt"
"sync"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/giantswarm/aws-operator/service/controller/legacy/v26/controllercontext"
)
const (
Name = "routetable... |
package mixmux
import (
"net/http"
"strings"
"github.com/dimfeld/httptreemux/v5"
)
// TreeMux wraps HTTPTreeMux.
type TreeMux struct {
t *httptreemux.TreeMux
path string
reg map[string][]string
}
// NewTreeMux returns a wrapped HTTPTreeMux.
func NewTreeMux(opts *Options) *TreeMux {
t := &TreeMux{
t: ... |
package main
type smallStruct struct {
a, b int64
c, d float64
}
func main() {
smallAllocation()
}
// The annotation //go:noinline will disable in-lining that would optimize the code by removing the function and,
// therefore, end up with no allocation.
//go:noinline
func smallAllocation() *smallStruct {
return... |
package build
import (
"runtime"
)
// Info represents all available build & runtime environment information.
type Info struct {
Version string `json:"version,omitempty"`
CommitHash string `json:"commit_hash,omitempty"`
BuildDate string `json:"build_date,omitempty"`
GoVersion string `json:"go_version,omitemp... |
package logging
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/sirupsen/logrus"
)
const (
AutoLogFile = "auto"
logDateFormat = "2006-01-02T15-04-05"
)
// FileHook to send logs to the trace file regardless of CLI level.
type FileHook struct {
// Logger is a reference to the internal Logger that thi... |
package main
import (
"time"
"github.com/clarketm/json"
log "github.com/sirupsen/logrus"
"github.com/streadway/amqp"
)
var conn *amqp.Connection
var ch *amqp.Channel
var init_err error
var password string
var status StatusFH
func init() {
log.Trace("Initialised rabbitmq package")
status = StatusFH{
LastFau... |
package controllers
import (
"fmt"
"github.com/garyburd/redigo/redis"
"quickstart/helper"
"quickstart/models"
"time"
)
func init() {
}
type PostController struct {
baseApiController
}
func (this *PostController) Prepare() {
this.baseApiController.Prepare()
schemaString := map[string]string{
"POST": `
... |
package main
import "fmt"
// InsertionSort sorts by insertion
func InsertionSort(A []int, display bool) []int {
var i, j int
n := len(A)
for j = 1; j < n; j++ {
if display && n <= 10 {
fmt.Printf("%v =>", A)
}
key := A[j]
i = j - 1
for i > -1 && A[i] > key {
A[i+1] = A[i]
if disp... |
package qqmeeting
import (
"bytes"
"crypto"
"crypto/hmac"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math/rand"
"net"
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// Describe A Request
type MeetingRequest... |
package main
import (
consulApi "github.com/hashicorp/consul/api"
vaultApi "github.com/hashicorp/vault/api"
"os"
"log"
"net/http"
"fmt"
)
const ServiceNameEnvKey = "SERVICE_NAME"
func main() {
//Setup a webserver that retrieves the configuration from Consul
http.HandleFunc("/", serve)
if err := http.List... |
package handler
import (
"sync/atomic"
)
var internalRequestCounter int64
func getNewRequestID() int64 {
return atomic.AddInt64(&internalRequestCounter, 1)
}
|
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... |
package pubsub_test
import (
"os"
"syscall"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/hellodhlyn/go-pubsub"
)
func TestSubscriber_SubscribeFunc_Success(t *testing.T) {
subscriber := pubsub.NewSubscriber(validQueue{})
// Send SIGTERM after 10 ms.
pid := os.Getpid()
go func() { time... |
/*
Copyright (c) 2018 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software... |
package riverntorch
import (
"bytes"
"fmt"
"sort"
"strings"
)
type Person struct {
//specifies the name of the person
Name string `yaml:"name"`
//specifies the time it takes for the person to cross.
Duration int `yaml:"minutes"`
}
//
// people that needs to cross river.
//
type RiverCrossers []*Person
//
/... |
package main
import (
"coolgo/oop/student1"
"fmt"
"gothinking/oop/student2"
)
func TestStudent1() {
s1 := student1.Student{}
s1.Init("John", 25, "cs")
s1.SayHi()
// Error: implicit assignment of unexported field 'name' in student1.Student
//s2 := student1.Student{"Aimi", 24, "math"}
//s2.SayHi()
//Error: ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.