text stringlengths 11 4.05M |
|---|
package main
import (
"context"
"fmt"
"io"
"log"
"net"
"time"
"google.golang.org/grpc"
"github.com/sheghun/go-grpc/calculator/calculatorpb"
)
const (
port = ":50051"
)
type server struct {
calculatorpb.UnimplementedCalculateServiceServer
}
func main() {
lis, err := net.Listen("tcp", port)
if err != ni... |
package rest
import (
"time"
"github.com/golang/protobuf/ptypes"
"fmt"
"github.com/jinmukeji/jiujiantang-services/pkg/rest"
proto "github.com/jinmukeji/proto/v3/gen/micro/idl/partner/xima/core/v1"
"github.com/kataras/iris/v12"
)
// AccountSignIn 账户登陆
type AccountSignIn struct {
Account string `json:"acc... |
// Copyright (c) 2020 Xiaozhe Yao & AICAMP.CO.,LTD
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package requests
import (
"fmt"
"log"
"github.com/autoai-org/aid/components/cmd/pkg/utilities"
"github.com/levigross/grequests"
)
// Client is the basic class for perf... |
package main
import (
"os"
"strconv"
"time"
)
func test(i int) {
println("IMY***********", i)
defer test(i*100000000000000000/137 + 11 + 253)
}
func main() {
cnt, _ := strconv.Atoi(os.Args[1])
for i := 0; i < cnt; i++ {
go test(1)
}
time.Sleep(120 * time.Second)
}
|
package main
import (
"fmt"
"net"
)
type EndPoint struct {
IP [4]byte
Port uint16
}
type RouteEntry struct {
conn net.Conn
ep EndPoint
restartchan chan bool
readychan chan bool
closechan chan bool
}
func NewEndPoint(ip net.IP, port uint16) *EndPoint {
ipbs := ip.To4()
ep := EndPoint... |
package anansi
import (
"errors"
"image"
"unicode/utf8"
)
// Bitmap is a 2-color bitmap targeting unicode braille runes.
type Bitmap struct {
Bit []bool
Stride int
Rect image.Rectangle
}
// Load the given bit data into the bitmap.
func (bi *Bitmap) Load(stride int, data []bool) {
h := len(data) / stride
... |
package confighandler
import (
"log"
toml "github.com/pelletier/go-toml"
)
type StreamjuryConfig struct {
SuperUserId int64
ChannelId int64
ApiKey string
ResultsAbsPath string
}
type TomlConfig struct {
StreamjuryConfig StreamjuryConfig
}
func LoadConfig(filedata []byte) TomlConfig {
config... |
package models
import (
"github.com/astaxie/beego/orm"
"math"
)
type Article struct {
Id int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
LikeNum int `json:"like_num"`
ShareNum int `json:"share_num"`
EvaluateNum int `json:"evaluate_num"`
UserId... |
package mat
import (
"github.com/eriklupander/rt/internal/pkg/calcstats"
"github.com/eriklupander/rt/internal/pkg/identity"
)
var IdentityMatrix = identity.Matrix
func NewIdentityMatrix() Mat4x4 {
m1 := NewMat4x4(make([]float64, 16))
// Does this really copy arrays
for i := 0; i < 16; i++ {
m1[i] = IdentityM... |
package models
import (
"database/sql"
"fmt"
"github.com/lempiy/echo_api/types"
)
type genre struct{}
var Genre *genre
func (g *genre) ReadByFilmID(filmID int) ([]types.Genre, error) {
var genres []types.Genre
var genre types.Genre
var rows *sql.Rows
querySQL := `SELECT g.id, g.name, g.added_at
... |
package initialize
import (
"fmt"
_ "github.com/mbobakov/grpc-consul-resolver" // it's important
uuid "github.com/satori/go.uuid"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer/roundrobin"
"os"
"os/signal"
"shop-web/user-api/global"
"shop-web/user-api/proto"
"shop-web/user-api/u... |
package pascal
const testVersion = 1
func Triangle(n int) [][]int {
if n < 1 {
panic("The parameter n must be >= 1.")
}
ret := make([][]int, n)
for i := 0; i < n; i++ {
length := i + 1
ret[i] = make([]int, length)
ret[i][0] = 1
ret[i][length-1] = 1
for j := 1; j <= i-1; j++ {
ret[i][j] = ret[i-1]... |
package msgpackdiff
import (
"bytes"
"encoding/base64"
"io/ioutil"
"reflect"
"testing"
"github.com/algorand/msgp/msgp"
)
func TestGetBinary(t *testing.T) {
type GetBinaryTest struct {
Name string
Input string
Expected []byte
}
algoTxn, err := ioutil.ReadFile("../test/algo_txn_binary")
if err ... |
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package testutil
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"syscall"
"testing"
"time"
)
// BuildMain builds the main package in the current wo... |
package main
import (
"context"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"grpc-training/calculator/calculatorpb"
"io"
"log"
"time"
)
const target = "localhost:50051"
func main() {
conn, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
log.Fatalf("Could not connect: %v",... |
package storage
import (
"context"
"errors"
"strings"
"github.com/dgraph-io/badger/v3"
"github.com/gernest/8x8/pkg/models"
)
var ErrNotFound = errors.New("Not found")
type Store interface {
User() User
}
type storeKey struct{}
func Set(ctx context.Context, v Store) context.Context {
return context.WithValu... |
package main
import (
"fmt"
)
func isOneBitCharacter(bits []int) bool {
size := len(bits)
i := 0
for i < size-1 {
if bits[i] == 1 { // 出现1必然是两比特
i += 2
} else {
i++
}
}
return i == size-1
}
func main() {
bits := []int{1, 0, 1, 1, 0}
fmt.Println(isOneBitCharacter(bits))
}
|
package prices
import (
"fmt"
"github.com/kainosnoema/terracost-cli/terraform"
)
var rdsInstanceClassMap = map[string]string{
"db.m4.10xlarge": "db.m4.10xl",
"db.m4.16xlarge": "db.m4.16xl",
"db.m5.xlarge": "db.m5.xl",
"db.m5.2xlarge": "db.m5.2xl",
"db.m5.4xlarge": "db.m5.4xl",
"db.m5.8xlarge": "db... |
package manifests
import (
"os"
"testing"
"github.com/golang/mock/gomock"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
hivev1 "github.com/openshift/hive/apis/hive/v1"
hivev1agent "g... |
package iotservice
// Result is a direct-method call result.
type Result struct {
Status int `json:"status,omitempty"`
Payload map[string]interface{} `json:"payload,omitempty"`
}
type Device struct {
DeviceID string `json:"deviceId,omitempty"`
GenerationID ... |
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obta... |
package utils
import (
"encoding/json"
"net/http"
"strconv"
)
const (
ERROR int = -1
WARNING int = 0
SUCCESS int = 1
)
func Message(status int, message string) map[string]interface{} {
return map[string]interface{}{"status": status, "message": message}
}
func Respond(w http.ResponseWriter, data map[string]... |
package main
import "math"
import s "strconv"
// . "lib/math" <= We ignore these imports
import (
"crypto/rand"
"fmt"
"time"
)
import "math/big"
import (
"text/template"
e "errors"
"path/filepath"
)
import (
"syscall"
"os"
)
import _ "strings"
import "sync"
import ( "bytes" )
const open_FLAGS = syscal... |
package database
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// initSqlite: Initialise sqlite DBHandle
func (db *Database) initSqlite() (err error) {
if db.DB, err = gorm.Open(sqlite.Open(db.Config["DB_NAME"]), &gorm.Config{}); err != nil {
return err
}
return nil
}
|
package data
import (
"../../p1"
"../../p2"
"sync"
)
// A synchronized BlockChain structure, that extends th normal BlockChain from P2
type SyncBlockChain struct {
bc p2.BlockChain
mux sync.Mutex
}
// Create a new instance of a sync BlockChain
func NewBlockChain() SyncBlockChain {
return SyncBlockChain{bc: p2... |
// Copyright 2023 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 handler
import (
"context"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jinmukeji/go-pkg/v2/crypto/rand"
"github.com/jinmukeji/jiujiantang-services/jinmuid/mysqldb"
smspb "github.com/jinmukeji/proto/v3/gen/micro/idl/partner/xima/sms/v1"
jinmuidpb "github.com/jinmukeji/proto/v3/gen/micr... |
package main
import (
//"golang.org/x/tools/go/ssa/interp/testdata/src/fmt"
"fmt"
"sync"
"time"
)
/*
@Time : 2020/5/24 1:48 下午
@Author : audiRS7
@File : 08_读写互斥锁
@Software: GoLand
*/
var (
x int64
wg sync.WaitGroup
lock sync.Mutex //互斥锁
rwlock sync.RWMutex //读写互斥锁:多个goroutine同时加读锁,写的时候加写锁
)
/*
读... |
package gofencer_test
import (
"reflect"
"testing"
"github.com/olliephillips/gofencer"
)
// Test data
type testPoint struct {
lat float64
lng float64
inside bool
}
func TestCheckPoint(t *testing.T) {
gf := new(gofencer.Geofence)
// Create test cases
var testPoints []testPoint
testPoints = append(te... |
package body
import "testing"
type resolveBodyArmorTypeTestPair struct {
input string
output EBodyArmorType
}
var resolveBodyArmorTypeTests = []resolveBodyArmorTypeTestPair{
{"", ""},
{"blah", ""},
{"Light", LGHT},
{"Medium", MEDM},
{"Compound", COMP},
{"Heavy", HEVY},
{"Barrier", BARR},
{"Shield", SHLD},... |
package models
type Group struct {
Model
code int64
}
func NewGroupModel() *Group {
return &Group{
Model: Model{TableName: "admin_group", PrimaryKey: "groupid"},
code: 1200,
}
}
func (g *Group) Valid(mData *map[string]string) (int64, string) {
d := *mData
if _, ok := d["name"]; !ok {
return g.code + 1, ... |
package models
import (
"github.com/astaxie/beego/orm"
"time"
)
type SomeNews struct {
NewsID int64 `orm:"column(Id);pk;auto"`
Title string `orm:"size(64)" json:"title"`
NewsINFO string `orm:"size(512)" json:"news_info"`
NewsUper string `json:"news_uper"`
NewsRemaker string `orm:"size(128)" ... |
package manage_product
import "github.com/jinzhu/gorm"
type Image struct {
gorm.Model
ImageURL string
ProductID uint
}
|
package main
import (
"testing"
)
type test struct {
l1 *node
l2 *node
a int
}
func buildTests() []test {
l1a := &node{0, &node{1, &node{2, &node{3, &node{4, nil}}}}}
l1b := &node{3, &node{5, &node{6, &node{7, &node{8, nil}}}}}
a1 := 3
t1 := test{l1a, l1b, a1}
l2a := &node{5, &node{3, &node{4, &node{9, &n... |
package main
import "golangPractice/chat_room/chat_server/model"
var(
mgr *model.UserMgr
)
func initUserMgr() {
mgr = model.NewUserMgr(pool)
}
|
package misc
import "encoding/json"
func messageReader(messages <-chan string) []string {
println("Waiting ..")
return []string{
<-messages,
<-messages,
<-messages,
}
}
// SendAndReadMessage sends a bunch of delayed pings.
func SendAndReadMessage() []string {
messages := make(chan string)
go DelayedPing(... |
package goldie
import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
"testing"
)
func TestGet(t *testing.T) {
Get["/no/params"] = func() string {
return "hello"
}
Get["/one/variable/{id}"] = func(m struct{ Id int }) string {
return strconv.Itoa(m.Id)
... |
package services
import (
"github.com/gophergala2016/source/core/foundation"
"github.com/gophergala2016/source/core/models"
)
type TagService struct {
RootService
}
func NewTagService(ctx foundation.Context) TagService {
return TagService{
RootService: NewRootService(ctx),
}
}
// GetTagByID get entity by id... |
package publisher
import "context"
type Publisher interface {
Publish(context.Context, []byte) error
Close() error
}
|
package net
import "Zinx/Project/Zinx/v3-Request/zinx/iface"
type Request struct {
conn iface.Iconnection
data []byte
len uint32
}
func NewRequest(conn iface.Iconnection, data []byte, len uint32) iface.IRequest {
return &Request{
conn: conn,
data: data,
len: len,
}
}
//实现方法
func (r *Request) GetConn() ... |
package utils
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
)
// ExecuteCC invoke chaincode
func ExecuteCC(client *channel.Client, ccID, fcn string, args [][]byte, endpoints []string) []byte {
response, err... |
package integrationtest_test
import (
"fmt"
"os"
"os/exec"
"path"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
"github.com/pborman/uuid"
_ "gorm.io/driver/sqlite"
)
var _ = Describe("Catalog", func() {
var (
originalDir... |
package rolling
// 桶定义
type Bucket struct {
Point float64 //累加数据值
Count int64 //累加次数
next *Bucket //指向下一个桶
}
// 累加数据
func (b *Bucket) Add(val float64) {
b.Point += val
b.Count++
}
// 重置桶
func (b *Bucket) Reset() {
b.Point = 0
b.Count = 0
}
// 返回下一个桶
func (b *Bucket) Next() *Bucket {
return b.next
}
// 包... |
package cmd
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/mauhftw/genialo/config"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// Define labelOption struct
type LabelsOptions struct {
Organization string
LabelFile string
Application string
T... |
package types
// thoughts on those boxed type for default value solution...
type (
Bool *bool
Integer *int
)
func newBool(val bool) Bool {
return &val
}
func newInteger(val int) Integer {
return &val
}
|
package p2p
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/qlcchain/go-qlc/chain/context"
"github.com/google/uuid"
"github.com/qlcchain/go-qlc/config"
)
func Test_StreamManager(t *testing.T) {
//bootNode config
dir := filepath.Join(config.QlcTestDataDir(), "p2p", uuid.New().String(), config.Qlc... |
package client
import (
"fmt"
"log"
"os"
"github.com/weibocom/steem-rpc/apis/networkbroadcast"
"github.com/weibocom/steem-rpc/steem"
"github.com/weibocom/steem-rpc/transactions"
"github.com/weibocom/steem-rpc/translit"
"github.com/weibocom/steem-rpc/types"
)
// Post add a post.
func (c *Client) Post(authorna... |
package ch01
import (
"sort"
"testing"
)
func TestEx13(t *testing.T) {
for _, c := range []struct {
in []int
want []int
}{
{in: []int{0, 1, 2}, want: []int{}},
{in: []int{1, 1, 2}, want: []int{1}},
{in: []int{6, 6, 1, 1, 2, 1, 1, 0, 2, 7, 7}, want: []int{1, 2, 6, 7}},
} {
intComparer := func(a []i... |
// You can edit this code!
// Click here and start typing.
package main
import (
"fmt"
)
//利用iota表示计算机存储单位
//iota 遇到一个const计数器会变为0
const (
m_bytes = 1 << (10 * iota)
m_kb = 1 << (10 * iota)
m_mb
m_g
)
func main() {
fmt.Println(m_bytes)
fmt.Println(m_kb)
fmt.Println(m_kb)
fmt.Println(m_g)
}
|
/*
Make a function that generates an array of 1,000 2-dimensional points, where both the x-coordinate and the y-coordinate are between 0.0 and 1.0. So (0.735, 0.167) and (0.456, 0.054) would be examples.
(Most computer languages have a simple random function that returns a double precision floating point number in thi... |
//策略是定下终点,然后往前去找最远的点,但是有一点要注意就是在往前找的时间,查找的范围要确保是无相同的
package main
//可以用动规,可以用暴力查找
//暴力查找,定好当前位置,然后往前找最远的,不过要注意查找的范围无相同((i-1)-c[i-1]+1)
//动规:https://blog.csdn.net/qq_38494372/article/details/80846954
//用left来跟踪到目前为止,没有出现重复段的最左边的字符,然后当出现重复字符的时候就判断下left与上一个重复字条之间的大小;如果上一个重复字符的位置在left的右边,就需要更新left;否则判断加上当前字符是否出现更大的长度值
fu... |
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"text/template"
"unicode"
"github.com/beeceej/protoform/protoform"
)
func main() {
inFile := flag.String("in-file", "", "Input File")
pkg := flag.String("package", "", "Package of proto")
out := flag.String("out-file", "", "Output File")
... |
package graph
import "errors"
// 邻接矩阵(稠密图,边多,eg:完全图(所有点都相连(边)))
type AdjacencyMatrix struct {
vertexs int // 点数
edges int // 边数
directed bool // 是否有向
graph [][]int // 矩阵(1:连接;0:不连接)
}
// 构造函数:参数:点数(0至n-1)和是否有向
func NewDenseGraph(vers int, directed bool) *AdjacencyMatrix {
g := new(AdjacencyMat... |
// All Rights Reserved.
//
// 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 models
import (
"encoding/json"
"time"
"github.com/markbates/pop"
"github.com/markbates/validate"
"github.com/markbates/validate/validators"
"github.com/satori/go.uuid"
)
type Show struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time... |
package public
import (
"context"
"tpay_backend/merchantapi/internal/common"
"tpay_backend/model"
"tpay_backend/merchantapi/internal/svc"
"tpay_backend/merchantapi/internal/types"
"github.com/tal-tech/go-zero/core/logx"
)
type UpdateBankCardLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.Serv... |
package main
import (
"fmt"
)
func main() {
//Connect with server name
serverName := new(ServerNameProxy)
serverName.Host = "localhost"
serverName.Port = "9090"
var t TrigonometryProxy
t = serverName.LookupTrigonometry("arithmetic")
fmt.Println("Aqui")
result := t.Tan(11)
fmt.Println("resul... |
package web
import (
"fmt"
"gosdk-example/sdkconnector"
"net/http"
)
//InstantiateCC handles chaincode instantiate API requests.
func (setups OrgSetupArray) InstantiateCC(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
orgN... |
package main
import (
"net"
"time"
)
type IPItemResponse struct {
IP net.IP
ConfirmID string
Err error
}
type IPItem struct {
IP net.IP
Expire time.Time
}
// Netmask 255.255.255.0 es wird nichts akzeptiert wie 255.0.255.255.255
type SubnetSpec struct {
Sub int
From net.IP
To net.IP
}
... |
package caaa
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document00200103 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:caaa.002.001.03 Document"`
Message *AcceptorAuthorisationResponseV03 `xml:"AccptrAuthstnRspn"`
}
func (d *D... |
package testsuite
import (
"context"
"testing"
"go.mercari.io/datastore/v2"
)
func geoPointPutAndGet(ctx context.Context, t *testing.T, client datastore.Client) {
defer func() {
err := client.Close()
if err != nil {
t.Fatal(err)
}
}()
// NOTE *datastore.GeoPoint is not officially supported by Datasto... |
package main
import (
//"fmt"
l4g "base/log4go"
"io/ioutil"
"net/http"
)
//协议注册方法
func InitHttpCommand() {
g_HttpCommandM.Register("log", UserLogCommand{})
}
type UserLogCommand struct {
}
func (this UserLogCommand) Execute(r *http.Request, p *HttpHandlerPool) bool {
re, _ := ioutil.ReadAll(r.Body)
//1.将数据反... |
package entity
import (
"github.com/mirzaakhena/danarisan/domain/vo"
"time"
)
type Undian struct {
BaseModel
ID vo.UndianID `gorm:"primaryKey"` //
ArisanID vo.ArisanID `json:"-"` //
PutaranKe int //
TanggalTagihan time.Time //
TanggalUndian time.Time //
BiayaAdmin... |
//Package entries contains structs of elements parsed in the XML files
package jmdict
import "encoding/xml"
/************************************************************************************************
* The goal of this is to successfully Marshal and Unmarshal kanjidic2 in the exact same format.
* This struct is... |
package syscallx
/* This is the source file for syscallx_darwin_*.go, to regenerate run
./generate
*/
// cannot use dest []byte here because OS X getxattr really wants a
// NULL to trigger size probing, size==0 is not enough
//
//sys getxattr(path string, attr string, dest *byte, size int, position uint32, optio... |
package testing
import (
"context"
"github.com/brigadecore/brigade/sdk/v3"
)
type MockLogsClient struct {
StreamFn func(
ctx context.Context,
eventID string,
selector *sdk.LogsSelector,
opts *sdk.LogStreamOptions,
) (<-chan sdk.LogEntry, <-chan error, error)
}
func (m *MockLogsClient) Stream(
ctx conte... |
/*
You have received an encrypted message from space. Your task is to decrypt the message with the following simple rules:
Message string will consist of capital letters, numbers, and brackets only.
When there's a block of code inside the brackets, such as [10AB], it means you need to repeat the letters AB fo... |
package game_map
import (
"fmt"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
"github.com/faiface/pixel/text"
"github.com/steelx/go-rpg-cgm/combat"
"github.com/steelx/go-rpg-cgm/gui"
"github.com/steelx/go-rpg-cgm/world"
"math"
"reflect"
)
type XPSummaryState struct {
win *pixelgl.Wind... |
package test_helpers
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
. "project/modules/helpers"
"reflect"
"strings"
)
type Request struct {
Url string `json:"-"`
Headers http.Header `json:"-"`
Request *http.Request `json:"-"`
Response *http.R... |
package cache
import "github.com/nicobianchetti/Go-CleanArchitecture/model"
//PermisoCache .
type PermisoCache interface {
Set(key string, value *model.Permiso)
Get(key string) *model.Permiso
}
|
package mysql
import "github.com/jmoiron/sqlx"
// Link is used to insert and update in mysql
type Link struct{}
// InitDB create db if not exists
func (link *Link) InitDB(exec sqlx.Execer, dbName string) (errExec error) {
_, errExec = exec.Exec(`CREATE DATABASE IF NOT EXISTS ` + dbName)
if errExec != nil {
retur... |
package mem
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"sync"
"github.com/aren55555/shepherd-backend/data"
"github.com/aren55555/shepherd-backend/models"
"github.com/google/uuid"
)
var _ data.Store = &Client{}
type Client struct {
*client
}
type client struct {
lock sync.RWMutex
for... |
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*
* file: dbhandler.go
* details: Initializes all the database handlers
*
*/
package dbhandler
import (
"net/http"
opts "github.com/Juniper/collector/query-api/options"
)
type Handler struct {
dbH dbHandler
}
type dbHandler interface {
... |
package main
import (
"net/http"
"os"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
"github.com/grafana/grafana-plugin-sdk-go/experimental"
)
func main() {
mux := http.New... |
/*Package openhashmap 是开地址哈希的实现,由于golang中map结构本身在底层
就是使用哈希表实现的,所以我们并不使用map结构来实现这一数据结构,
冲突解决的办法使用双散列,因为它的产生的元素分布比其他几种办法如
线性探测或平方探测都好。*/
package openhashmap
import "fmt"
type openHashMap struct {
bucketsize int //槽位数量
itemsize int //元素数目
bucket []int
}
//Hash 使用双散列解决冲突
func (h *openHashMap) Hash(item int, i i... |
package modules
import (
"fmt"
"time"
"unicode"
"unicode/utf8"
"github.com/jinzhu/inflection"
)
// gen:qs
type CircleUnit struct {
ID uint `description:""`
CreatedAt time.Time `description:"등록일"`
UpdatedAt time... |
package options
// PolicyOptions is the option aggregate structure for options for policy
// apply operations.
type PolicyOptions struct {
Subpath string
SnapshotName string
Action string
FileListPrefix string
QoSClass string
NodeList []string
GlobalWor... |
// This file was generated for SObject Note, API Version v43.0 at 2018-07-30 03:48:05.530325403 -0400 EDT m=+51.874878322
package sobjects
import (
"fmt"
"strings"
)
type Note struct {
BaseSObject
Body string `force:",omitempty"`
CreatedById string `force:",omitempty"`
CreatedDate string ... |
package commit
import "time"
// State is the state of a collection at a point in time.
type State struct {
Time time.Time `json:"time"`
Instance string `json:"instance"`
StateData
}
|
package friend
import "spapp/src/models/apimodels"
type BlockUserInput struct {
Requestor string `json:"requestor"`
Target string `json:"target"`
}
type BlockUserOutput struct {
apimodels.ApiResult
} |
package intlog
import (
"fmt"
"log"
"time"
"dream01/internal/lumberjack"
)
// IntLogger ...
type IntLogger struct {
l *lumberjack.Logger
}
// NewIntLogger ...
func NewIntLogger(l *lumberjack.Logger) *IntLogger {
return &IntLogger{
l: l,
}
}
// Write ...
func (ml *IntLogger) Write(p []byte) (n int, err err... |
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"log"
"os"
"github.com/kardianos/osext"
)
type Person struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Address *Address `json:address,omitempty`
}
type Address struct {
City string `json:"city"`... |
package helloworld
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"go.coder.com/hat"
"go.coder.com/hat/asshat"
)
func TestAPI(tt *testing.T) {
s := httptest.NewServer(&API{})
defer s.Close()
t := hat.New(tt, s.URL)
t.Run("Hello Echo single-parent chain", func(t *... |
package main
import (
"archive/zip"
"fmt"
"github.com/kjk/lzmadec"
"github.com/pkg/errors"
"io"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
)
type PullService struct{
BoneTomeMetadata *BoneTomeMetadata
TempDirectory string
}
func (ps *PullService) download(btmd *BoneTomeMetadata) {
resp, err... |
package Router
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/masbagas23/octopus"
)
func router() *gin.Engine {
router := gin.Default()
user := router.Group("/user")
{
user.GET("/get", UserController.GetUser)
}
return router
}
|
package main
import (
"backend/base"
"backend/conf"
"backend/models"
"backend/utils/gredis"
"backend/utils/setting"
"fmt"
"net/http"
)
func main() {
conf.Init()
setting.Setup()
models.Setup()
_ = gredis.Setup()
router := base.InitRouter()
s := &http.Server{
Addr: fmt.Sprintf(":%d", setting.S... |
package task
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
)
const defaultTaskfile = `# https://taskfile.dev
version: '2'
vars:
GREETING: Hello, World!
tasks:
default:
cmds:
- echo "{{.GREETING}}"
silent: true
`
// InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(w io.W... |
package controllers
import (
"encoding/json"
//"errors"
"fmt"
"github.com/deepglint/nsqelastic/models"
"io/ioutil"
"net/http"
"strings"
)
type NsqController struct {
Config *models.ConfigModel
TopicChan2NodeItemMap *models.BigTable
Topic2TopicItemMap *models.BigTable
NodeItem2NodeMap ... |
package neworderlist
import (
"github.com/shopspring/decimal"
"time"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/enum"
"github.com/quickfixgo/quickfix/field"
"github.com/quickfixgo/quickfix/fix41"
"github.com/quickfixgo/quickfix/tag"
)
//NewOrderList is the fix41 NewOrderList type, MsgTyp... |
package gen
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
)
// Loader is the contract required to be able to resolve a schema.
type Loader interface {
io.Closer
// Read returns a schema for a URL
Load(ctx context.Context, u *url.URL) (*Schema, error)
}
// NewLoader returns a basic... |
/*
*by wayyoung
题目:二维数组中的查找
在一个二维数组中(每个一维数组的长度相同),
每一行都按照从左到右递增的顺序排序,每一列都
按照从上到下递增的顺序排序。请完成一个函数,输
入这样的一个二维数组和一个整数,判断数组中是否
含有该整数。
*解题思路:
整体结构为:
小1.。。。。大1
小2.。。。。大二
但是每行独立来看都是独立的,因为大1不一定小于小2
所以直接判断头尾就行,
若小x>目标数字时已经决定了之后的数组肯定不会再存
在目标数字,可以直接跳出
*/
package _go
import (
)
func so0(target int,array [][]int) bool {
if len... |
package bosh
import (
"reflect"
"testing"
"time"
"github.com/skriptble/nine/element"
"github.com/skriptble/nine/stream"
)
func TestSessionWrite(t *testing.T) {
t.Parallel()
var el, want, got element.Element
var err error
var rsp chan element.Element
var exit chan struct{}
var s *Session
// Should return... |
package fp
import (
"path/filepath"
"testing"
)
func TestJoin(t *testing.T) {
t.Log(filepath.Join("", "hello.txt"))
t.Log(filepath.Join("", ".hello"))
in := filepath.Join("", ".hello")
out, err := filepath.Abs(in)
t.Log("in:", in, "out:", out, "err:", err)
}
|
package memrepo
import (
"github.com/scjalliance/drivestream"
"github.com/scjalliance/drivestream/fileversion"
"github.com/scjalliance/drivestream/fileview"
"github.com/scjalliance/drivestream/resource"
)
var _ drivestream.FileReference = (*File)(nil)
// File is a drivestream file reference for an in-memory repo... |
package main
import "fmt"
// 5. 最长回文子串
// 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。
// https://leetcode-cn.com/problems/longest-palindromic-substring/
func main() {
fmt.Println(longestPalindrome2("baba"))
}
// 法一:暴力+双指针
// 枚举回文串中心,双指针向两侧扩展
// best
func longestPalindrome(s string) (result string) {
n := len(s)
... |
package suites
import (
"time"
)
var multiCookieDomainSuiteName = "MultiCookieDomain"
var multiCookieDomainDockerEnvironment = NewDockerEnvironment([]string{
"internal/suites/docker-compose.yml",
"internal/suites/MultiCookieDomain/docker-compose.yml",
"internal/suites/example/compose/authelia/docker-compose.back... |
package main
//voila we have reached the HTML templating
import (
"fmt"
"html/template"
"net/http"
)
//generating a struct to pass data to the html files
type NewsAggPage struct {
Title string
News string
}
//a basic index page , this is not a template
func index_handlertemp(w http.ResponseWriter, r *http.Req... |
package db
/**
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"database/sql"
)
var con *sql.DB
func init() {
var err error
con, err = sql.Open("mysql", "root:@/test")
//defer con.Close()
if err != nil {
panic(err)
}
}
func Start() {
fmt.Printf("%s#\n", get())
fmt.Printf("%s#\n", getById(2))
}
... |
// Copyright 2015 The Prometheus 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... |
package main
import (
"fmt"
"time"
)
func fibonacci(n int) int {
if n < 2 {
return n
}
return fibonacci(n-2) + fibonacci(n-1)
}
func main(){
var i int
start := time.Now()
for i = 0; i < 40; i++ {
fmt.Printf("%d\t", fibonacci(i))
}
times := time.Since(start)
fmt.Println("times",times)
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.