text stringlengths 11 4.05M |
|---|
package rabbitmq
import (
_ "fmt"
_ "github.com/tidwall/gjson"
_ "io/ioutil"
)
type Conn struct {
Url string `json:"url"`
}
|
package main
import "fmt"
func main() {
slice1 := []int{1, 2, 3}
slice2 := make([]int, 2) // define a slices, 2 is number of "room for element"
copy(slice2, slice1)
fmt.Println(slice1, slice2)
x := [6]string{"a", "b", "c", "d", "e", "f"}
fmt.Println(x[2:5])
}
|
package main
import "fmt"
func main() {
card := newCard()
fmt.Println(card)
}
// golang function and return type of function.
func newCard() string {
return "Ace of Diamond"
}
|
package v1alpha1_test
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/experimental/workflows/pkg/apis/workflows/v1alpha1"
"github.com/tektoncd/experimental/workflows/test/parse"
"knative.dev/pkg/apis"
)
func TestValidateFilters(t *testing.T) {
tcs := []struct {
name strin... |
// Copyright 2019 - 2022 The Samply Community
//
// 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 ... |
package main
import (
"advent-2015/utils"
"fmt"
"regexp"
"strconv"
)
func main() {
input := utils.ReadLines("./day07/input.txt")
c := NewCircuit(input)
fmt.Println("------- Part 1 -------")
a := c.GetValue("a")
fmt.Printf("After running the circuit, wire a has signal value %d\n\n", a)
fmt.Println("-------... |
// Copyright 2017 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wast
import (
"fmt"
"unicode"
)
type Pos struct {
Line, Column int
}
type Token struct {
Kind TokenKind
Pos Pos
Text string
V... |
package dgraph
import (
"context"
"encoding/json"
"fmt"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"google.golang.org/grpc"
)
var Client *dgo.Dgraph
var Connection *grpc.ClientConn
func init() {
Open("127.0.0.1:9080")
err := CreateSchema()
if err != nil {
fmt.Println("Error while cr... |
package main
import (
"flag"
"fmt"
"github.com/drjerry/nnetlab/core"
"log"
"os"
)
type Args struct {
dataStream *os.File
initialConfig string
finalConfig string
// training-related arguments
testMode bool
lossFunction string
learnRate float32
batchSize int
quiet bool
}
var (
pars... |
package controllers
import (
"fmt"
"io"
"os"
"path/filepath"
"time"
"github.com/itang/gotang"
"github.com/itang/yunshang/main/app/models"
"github.com/itang/yunshang/main/app/models/entity"
"github.com/itang/yunshang/main/app/routes"
"github.com/itang/yunshang/main/app/utils"
"github.com/lunny/xorm"
"githu... |
package buildInfo
import (
"fmt"
"github.com/mitchellh/cli"
)
// CommandT is a Command implementation that returns version information
type CommandT struct {
bi *BuildInfo
ui cli.Ui
}
// Command Builds and returns a CommandT struct
func (bi *BuildInfo) Command(ui cli.Ui) (*CommandT, error) {
return &CommandT{
... |
package main
import "fmt"
func main() {
//var m1 map[string]int
//m2 := make(map[int]interface{},100)
m3 := map[string]string{
"name":"james",
"age":"35",
}
//m1["key1"] = 1
//m2[1] = 1
m3["key1"] = "v1"
m3["key2"] = "v2"
m3["key3"] = "v3"
m3["key3"] = "v0"
//fmt.Println(len(m3))
//
//fmt.Println(... |
package main
import (
"nes"
"os"
"log"
)
func main() {
var file *os.File
var err error
if file, err = os.Open("assets/nestest.nes"); err != nil {
log.Fatal(err)
return
}
var rom *nes.ROM
rom, err = nes.ReadROM(file)
if err != nil {
log.Fatal(err)
... |
// Package nats provides sample codes for NATS/STAN client/server.
package nats
// RunClient runs STAN client
func RunClient() {
var err error
DispMsg(TypeReq, "run STAN client", err)
}
|
package bike
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBattleMsg(t *testing.T) {
ast := assert.New(t)
msg := `91A14694 :参戦ID
参加者募集!
Lv10 ユグドラシル・マグナ`
ast.True(IsGBFBattle(msg))
msg = `2F1E6FF1 :参戦ID
参加者募集!
黄龍・黒麒麟HL`
ast.True(IsGBFBattle(msg))
}
func TestBattleMsgFail(t *testing.T) {
... |
package brackets
import "testing"
type testCase struct {
name string
input string
want bool
}
var testCases = []testCase{
{"0", "{[()]}", true},
{"1", "{[(])}", false},
{"2", "{{[[(())]]}}", true},
{"3", "}{}{}", false},
{"4", "[](){}", true},
}
func TestBalanced(t *testing.T) {
for _, tc := range testCa... |
package main
import(
"errors"
"fmt"
)
func main(){
pilha:=Pilha{} // criamos uma instância da pilha e atribuímos o objeto retornado à variável 'pilha'.
fmt.Println("Pilha criada com tamanho ",pilha.Tamanho())
fmt.Println("Vazia? ",pilha.Vazia())
pilha.Empilhar("Go")
pilha.Empilhar(2009)
pilha.Empilhar(3.14)
... |
package pandaTvAPI
import (
"testing"
)
var c *client
func Test_newClient(t *testing.T) {
var err error
c, err = newClient("__guid=96554777.1566464319758375400.1481558348791.0151; R=r%3D22412424%26u%3DCnaqnGi22412424%26n%3D%25R8%25OS%2599%25R4%25O8%258Q%25R6%2598%25NS%25R6%2588%2591%25R7%259N%2584%25R7%259O%258N... |
package retry
import (
"runtime"
"testing"
"time"
)
func TestRetry(t *testing.T) {
backoff := 20 * time.Millisecond
{
cnt := 0
now := time.Now()
err := Retry(ConstantBackoffs(5, backoff), func() (State, error) {
cnt++
return Continue, ErrNeedRetry
})
assert(t, true, err != nil)
assert(t, cnt, 6... |
package main
import (
"fmt"
"sync"
)
func main() {
values := []string{"a", "b", "c"}
var wg sync.WaitGroup
for _, v := range values {
wg.Add(1)
go func() {
fmt.Println(v)
wg.Done()
}()
}
wg.Wait()
}
|
// Copyright 2019 The gVisor 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 agree... |
package storage
import (
"encoding/binary"
"errors"
"io"
"os"
sm "github.com/lni/dragonboat/v3/statemachine"
"github.com/tecbot/gorocksdb"
)
var indexKeyCf = "__index_default_cf__"
var indexKeyPrefix = []byte("disk_kv_applied_index")
type RocksDBStateMachine struct {
ClusterID uint64
NodeID uin... |
package cluster
import "github.com/cohesity/management-sdk-go/models"
import "github.com/cohesity/management-sdk-go/configuration"
/*
* Interface for the CLUSTER_IMPL
*/
type CLUSTER interface {
UpdateCluster (*models.UpdateCluster) (*models.CohesityCluster, error)
GetCluster (*bool) (*models.Co... |
package beachfront
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/prebid/openrtb/v19/adcom1"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github... |
package task
import (
"fmt"
"github.com/mizuki1412/go-core-kit/library/commonkit"
"github.com/mizuki1412/go-core-kit/service/cronkit"
"github.com/mizuki1412/go-core-kit/service/influxkit"
"github.com/spf13/cast"
"jd-mining-server/service"
"jd-mining-server/service/config"
"jd-mining-server/service/model"
"jd-... |
package command
import (
"fmt"
"strings"
"github.com/lets-cli/lets/util"
)
var (
CMD = "cmd"
DESCRIPTION = "description"
ENV = "env"
EvalEnv = "eval_env"
OPTIONS = "options"
DEPENDS = "depends"
CHECKSUM = "checksum"
PersistChecksum = "persist_chec... |
package protocol
import (
"fmt"
mintcommon "mint-server/common"
"mint-server/config"
"net"
"github.com/golang/protobuf/proto"
)
type functionType string
const (
WELCOME functionType = "Welcome"
SIGNIN functionType = "SignIn"
SIGNUP functionType = "SignUp"
UNKNOWN functionType = "Unknown"
... |
/*
* Databricks
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 0.0.1
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package models
type ClustersClusterState string
// List of ClustersClusterSta... |
package subset
import "testing"
type testCase struct {
name string
k int32
set []int32
ans int32
}
var testCases = []testCase{
{"0", 4, []int32{19, 10, 12, 10, 24, 25, 22}, 3},
{"1", 3, []int32{1, 7, 2, 4}, 3},
{"2", 5, []int32{6, 7, 8, 9, 10, 11, 12}, 5},
}
func TestNonDivisibleSubset(t *testing.T) {
... |
package routers
import (
"eff/controllers"
"github.com/astaxie/beego"
)
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/dah", &controllers.Dah{})
beego.Router("/dah/delete/:id([0-9]+)", &controllers.Dah{}, "get:Delete")
beego.Router("/dah/status", &controllers.Dah{}, "get:Status")... |
package localregistry
import (
"context"
"time"
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/... |
//nolint:dupl
package mongodb
import (
"context"
"errors"
"github.com/joshprzybyszewski/cribbage/model"
"github.com/joshprzybyszewski/cribbage/server/interaction"
"github.com/joshprzybyszewski/cribbage/server/persistence"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mong... |
package main
/*
Developed by "https://github.com/vitorfmc"
=======================================================
Overview:
=======================================================
This Lambda Function is example of integration with DynamoDB.
The idea is make a insert into DB.
Obs.: Rememb... |
// Update view - updates already installed dotfiles
// =================================================
package views
import (
"net/http"
"text/template"
)
type UpdateData struct {
ClientSecret string
RepoOpts string
BaseURL string
URLMask string
}
func ServeUpdate(w http.ResponseWriter, r *h... |
package gore
import (
"os"
"testing"
)
func init() {
if os.Getenv("TEST_REDIS_CLIENT") != "" {
shouldTest = true
}
}
func TestPool(t *testing.T) {
if !shouldTest {
return
}
conn, err := Dial("localhost:6379")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
pool := &Pool{
InitialConn: 5,
Maxi... |
package piscine
import "github.com/01-edu/z01"
func PrintNbrInOrder(n int) {
if n < 0 {
return
}
if n == 0 {
z01.PrintRune('0')
}
var array [10]int // creating an array to append
for n != 0 {
array[n%10]++
n /= 10
}
for i := 0; i < 10; i++ {
for array[i] > 0 {
z01.PrintRune(rune(i) + '0')
... |
package spacelift
import (
"fmt"
"sort"
"strings"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
e "github.com/cloudposse/atmos/internal/exec"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
s "github.com/cloudposse/atmos/pkg/stack"
u "github.com/cloudposs... |
// Package frames implements HTTP/2 frames exchanged by peers as defined in
// RFC 7540 Section 6.
package frames
import (
"errors"
"fmt"
"github.com/jamescun/http2/settings"
)
var (
// ErrFrameTooBig is returned when attempting to marshal a Frame but its
// configured length exceeds a uint24.
ErrFrameTooBig =... |
package smartcontractdatastore
import (
"fmt"
"github.com/multivactech/MultiVAC/model/chaincfg/multivacaddress"
"github.com/multivactech/MultiVAC/model/merkle"
"github.com/multivactech/MultiVAC/model/shard"
"github.com/multivactech/MultiVAC/model/wire"
"github.com/multivactech/MultiVAC/processor/shared/state"
)... |
package strategies
import (
"github.com/matang28/reshape/reshape"
"github.com/matang28/reshape/reshape/sinks"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDirectStrategy_Solve_HappyCase(t *testing.T) {
strg := NewDirectStrategy()
src := make(chan interface{})
sink := sinks.NewArraySink()
go strg... |
package tests
import (
"testing"
)
/**
* [64] Minimum Path Sum
*
* Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
*
* Note: You can only move either down or right at any point in time.
*
* Example:
*
*
* ... |
package consumer
import (
"fmt"
"hash/crc32"
"os"
"runtime/debug"
"sort"
"strings"
"sync"
"time"
"github.com/couchbase/eventing/common"
"github.com/couchbase/eventing/dcp"
mcd "github.com/couchbase/eventing/dcp/transport"
"github.com/couchbase/eventing/dcp/transport/client"
"github.com/couchbase/eventing... |
package requestid
import (
"context"
"net/http"
httputil "github.com/ahmedalhulaibi/httpfw"
"github.com/google/uuid"
)
const ContextKey = "request_id"
type requestIDExtractor interface {
GetRequestID(r *http.Request) string
}
type RequestIDMiddleware struct {
h http.Handler
ridex requestIDExtractor
}
f... |
package goserver
import (
"fmt"
"github.com/jmoiron/sqlx"
)
// UserRepoSqlite3 fulfills UserRepo using a Sqlite3 database
type UserRepoSqlite3 struct {
db *sqlx.DB
insertStmt *sqlx.NamedStmt
updatePasswdStmt *sqlx.NamedStmt
getByIDStmt *sqlx.NamedStmt
getByUsernameStmt *sqlx.Named... |
package main
// Leetcode 292. (easy)
func canWinNim(n int) bool {
return (n % 4) != 0
}
|
package handlers
import (
"net/http"
"path"
"plugin"
"github.com/layer5io/meshery/models"
)
var (
extendedEndpoints = make(map[string]*models.Router)
)
func (h *Handler) ExtensionsEndpointHandler(w http.ResponseWriter, req *http.Request, prefObj *models.Preference, user *models.User, provider models.Provider) ... |
package model
import (
"reflect"
"testing"
)
type CompareTest struct {
A reflect.Value
B reflect.Value
E bool
}
func TestConstant_EqualsTo(t *testing.T) {
tl := make([]*CompareTest, 0)
tl = append(tl, &CompareTest{
A: reflect.ValueOf(12),
B: reflect.ValueOf(12),
E: true,
}, &CompareTest{
A: reflect.... |
package router
import (
"github.com/1071496910/simple-http-router/lib/dispatcher"
"net/http"
"path/filepath"
"sync"
)
type Route struct {
route map[string]map[string]http.Handler
dps map[string]dispatcher.Dispatcher
mtx sync.Mutex
filters []filterFunc
}
type filterFunc func(rw http.ResponseWriter, ... |
package example1
import "errors"
type Opener interface {
Open(c *Connection) error
}
type Closer interface {
Close(c *Connection) error
}
type StateManager interface {
Opener
Closer
}
type Connection struct {
state StateManager
}
func (c *Connection) Open() error {
return c.state.Open(c)
}
func (c *Connec... |
package db
import (
"database/sql"
"fmt"
"os"
"github.com/joho/godotenv"
_ "github.com/lib/pq"
)
func loadDotEnv(key string) string {
err := godotenv.Load(".env")
if err != nil {
panic(error(err))
}
return os.Getenv(key)
}
// ConnSQL is a function to connect with database
func ConnSQL() *sql.DB {
host ... |
package scan
import (
"database/sql"
"fmt"
"reflect"
)
// ErrOneRow is returned by Row scan when the query returns more than one row
var ErrOneRow = fmt.Errorf("sql/scan: expect exactly one row in result set")
// Readable provides a scannable interface
type Readable interface {
Scan(interface{}) error
}
// Scan... |
package db
import (
"fmt"
"time"
"gin-use/configs"
"gorm.io/driver/postgres"
"github.com/pkg/errors"
"gorm.io/gorm"
)
var _ Repo = (*dbRepo)(nil)
type Repo interface {
i()
GetDbR() *gorm.DB
GetDbW() *gorm.DB
DbRClose() error
DbWClose() error
}
type dbRepo struct {
DbR *gorm.DB
DbW *gorm.DB
}
func New(... |
/*
* openapi-ipify
*
* OpenAPI client for ipify, a simple public IP address API
*
* API version: 3.3.1-pre.0
* Contact: blah@cliffano.com
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
import (
"net/http"
"github.com/gin-gonic/gin"
)
// GetIp - Get your public IP add... |
/*
* Copyright (c) zrcoder 2019-2020. All rights reserved.
*/
package longest_increasing_path_in_a_matrix
import "math"
/*
给定一个整数矩阵,找出最长递增路径的长度。
对于每个单元格,你可以往上,下,左,右四个方向移动。 你不能在对角线方向上移动或移动到边界外(即不允许环绕)。
示例 1:
输入: nums =
[
[9,9,4],
[6,6,8],
[2,1,1]
]
输出: 4
解释: 最长递增路径为 [1, 2, 6, 9]。
示例 2:
输入: nums =
[
[3,4,5],
[3,... |
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package graphics
import (
"context"
"os"
"path/filepath"
"time"
"chromiumos/tast/common/testexec"
"chromiumos/tast/local/upstart"
"chromiumos/tast/shutil"
"chromium... |
package ch13
import "container/heap"
type RouteHeap []Route
func (h RouteHeap) Len() int { return len(h) }
func (h RouteHeap) Less(i, j int) bool { return h[i].Price < h[j].Price }
func (h RouteHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *RouteHeap) Push(x interface{}) {
*h = append(*h,... |
package gotification_test
import (
"github.com/mikegw/gotification/pkg/notification"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("SQS", func(){
Describe("SQSPersistor", func(){
It("sends the persisted model to SQS", func(){
mockSender := notification.MockMessageSender{}
... |
package main
import "sort"
func p12933(n int64) int64 {
var tmp []int
var ret int64
for n > 0 {
tmp = append(tmp, int(n%10))
n /= 10
}
sort.Ints(tmp)
// sort.Sort(sort.Reverse(sort.IntSlice(tmp)))
for i := len(tmp) - 1; i >= 0; i-- {
ret *= 10
ret += int64(tmp[i])
}
return ret
}
|
package main
import (
"fmt"
"io"
"net"
"os"
"strconv"
)
func main() {
address := "localhost:9999"
tcpAddr, err := net.ResolveTCPAddr("tcp4", address)
fmt.Println(tcpAddr)
if err != nil {
fmt.Println("err in resolve: ", err)
}
listener, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
fmt.Println(... |
package constants
const (
OpenIDCTestStatusPort = 6922
CertmanagerPortNumber = 6940
AcmeProxyPortNumber = 6941
AcmePath = "/.well-known/acme-challenge"
AcmeProxyCleanupResponses = "/api/responses/cleanup"
AcmeProxyRecordResponse = "/api/responses/recordOne"
OpenIDCConfigurationDocumentPat... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package camera
import (
"context"
"time"
"chromiumos/tast/common/media/caps"
"chromiumos/tast/local/bundles/cros/camera/hal3"
"chromiumos/tast/local/chrome"
"chromium... |
package main
import (
"github.com/sfreiberg/gotwilio"
"log"
"strconv"
"strings"
)
func send(cl *gotwilio.Twilio, from string, to string, body string) {
var messages []string
if len(body) < 1500 {
messages = append(messages, body)
} else {
messages = splitLongBody(body)
}
for _, message := range messag... |
package k8sstatus
import (
"context"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
binddnsv1 "github.com/bind-dns/binddns-operator/pkg/apis/binddns/v1"
"github.com/bind-dns/binddns-operator/pkg/kube"
"github.com/bind-dns/binddns-operator/pkg/utils"
)
func UpdateDomainStatus(zone string, status binddnsv1.DomainStat... |
/*
* @lc app=leetcode id=42 lang=golang
*
* [42] Trapping Rain Water
*
* https://leetcode.com/problems/trapping-rain-water/description/
*
* algorithms
* Hard (48.22%)
* Likes: 7426
* Dislikes: 128
* Total Accepted: 530.5K
* Total Submissions: 1.1M
* Testcase Example: '[0,1,0,2,1,0,1,3,2,1,2,1]'
*
... |
package insights
import (
"context"
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"strings"
"time"
"github.com/dolittle/platform-api/pkg/platform"
platformK8s "github.com/dolittle/platform-api/pkg/platform/k8s"
"github.com/dolittle/platform-api/pkg/platform/mongo"
"github.com/dolittle/platform-api/pkg/uti... |
package undertone
import (
"encoding/json"
"github.com/prebid/prebid-server/openrtb_ext"
"testing"
)
func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json schema. %v", err)
}
for _, validPa... |
package factory
import (
"encoding/json"
"fmt"
"github.com/mitchellh/cli"
"seeder/constants"
"seeder/models"
"seeder/services"
"seeder/tools"
"seeder/utils"
"time"
)
func Destroy() (cli.Command, error) {
destroy := &destroyCommandCLI{}
return destroy, nil
}
type destroyCommandCLI struct {
Args []string
}... |
package main
import (
"fmt"
"isshe/algo"
)
func main() {
stack := algo.NewStack()
stack.Push(123, "isshe")
fmt.Println(stack.Top())
fmt.Println(stack.Pop())
fmt.Println(stack.Top())
fmt.Println(stack.Size())
fmt.Println(stack.IsEmpty())
fmt.Println(stack.Pop())
fmt.Println(stack.IsEmpty())
}
|
/*
git2sqlite - converts git repositories to sqlite databases.
When ran against a git repository, will output an sqlite database
with the following tables:
refs :: <path, hash>
blobs :: <hash, content>
trees :: <hash, content>
commits :: <hash, content>
This project i... |
package voronoi
func Number() int {
return 42
}
|
package builder
import (
"archive/tar"
"bytes"
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/go-logr/logr"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/layout"
"github.com/google/go-co... |
package main
//go:generate go run scripts/includedict.go
import (
"flag"
"fmt"
"log"
"math/rand"
"strings"
"time"
)
var numWords = flag.Int("num-words", 4, "number of words to use")
var number = flag.Bool("number", false, "replace a random character with a number")
var capitalize = flag.Bool("capitalize", fals... |
package pb
import (
"time"
"github.com/fanaticscripter/EggContractor/util"
)
func (c *SoloContract) GetDurationUntilProductionDeadline() time.Duration {
return util.DoubleToDuration(c.SecondsUntilProductionDeadline)
}
func (c *SoloContract) GetDurationUntilCollectionDeadline() time.Duration {
return util.Double... |
package i18n
import (
"strings"
"github.com/windrivder/gopkg/errorx"
)
var errUnmarshalNilLocate = errorx.New("can't unmarshal a nil *Locate")
type Locale int
const (
LocaleEN Locale = iota
LocaleZH
)
var (
locates = [...]string{
LocaleEN: "en",
LocaleZH: "zh",
}
)
func (l Locale) Int() int {
return i... |
package controllers
import (
"go_simpleweibo/config"
"go_simpleweibo/routes/named"
"net/http"
"github.com/gin-gonic/gin"
)
// Redirect : 路由重定向 use path
func Redirect(c *gin.Context, redirectPath string, withRoot bool) {
path := redirectPath
if withRoot {
path = config.AppConfig.URL + redirectPath
}
redire... |
// Copyright 2019 TriggerMesh, 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 t... |
package main
import (
"mall/app/api/web/system/conf"
"mall/app/api/web/system/server/http/server"
)
func main() {
if err := conf.Init(); err != nil {
panic(err)
}
server.Init(conf.Conf)
}
|
/*
* Copyright 2019-2020 VMware, 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 w... |
//go:generate mockery -name=Purchaser -output=./internal/mocks
package purchasepersister
import (
"context"
"encoding/json"
"errors"
"net/http"
"github.com/diegoholiveira/bookstore-sample/pkg/http/render"
"github.com/diegoholiveira/bookstore-sample/purchases"
)
type (
Purchaser interface {
MakePurchase(con... |
package main
import (
"fmt"
"os"
gcp_memberlist "github.com/stefanhans/cloud-function-play/memberlist"
)
var (
gcpMemberList *gcp_memberlist.Memberlist
)
// CreateMemberlist creates a memberlist regarding GCP Cloud Functions with Firestore
func CreateMemberlist(name, ip string) (*gcp_memberlist.Memberlist, erro... |
package main
import (
"testing"
)
func TestCode(t *testing.T) {
var tests = []struct {
input [][]int
output bool
}{
{
input: [][]int{
{0, 2, 1},
{1, 1, 1},
{2, 0, 0},
},
output: true,
},
{
input: [][]int{
{1, 3, 1},
{2, 1, 2},
{3, 3, 3},
},
output: false,
},
... |
package httpbot
import (
"fmt"
"log"
"os"
"util"
"golang.org/x/net/websocket"
)
type VideoClient struct {
r *Robot
msgChan chan []byte
debug bool
logger *log.Logger
}
func NewVideoClient(r *Robot, maxBuffer int, debug bool) *VideoClient {
return &VideoClient{
r: r,
msgChan: make(chan []b... |
// carbon-relay-ng
// route traffic to anything that speaks the Graphite Carbon protocol,
// such as Graphite's carbon-cache.py, influxdb, ...
package main
import (
"bufio"
"errors"
"flag"
"fmt"
"github.com/BurntSushi/toml"
"github.com/Dieterbe/statsd-go"
"github.com/graphite-ng/carbon-relay-ng/admin"
"github.... |
package extract
import (
"context"
"errors"
"io"
)
func copyCancel(ctx context.Context, dst io.Writer, src io.Reader) (int64, error) {
return io.Copy(dst, newCancelableReader(ctx, src))
}
type cancelableReader struct {
ctx context.Context
src io.Reader
}
func (r *cancelableReader) Read(p []byte) (int, error) ... |
package scanner
import (
"github.com/morlay/gin-swagger/program"
"go/ast"
"go/types"
"regexp"
"strings"
)
func isGinMethod(method string) bool {
var ginMethods = map[string]bool{
"GET": true,
"POST": true,
"PUT": true,
"PATCH": true,
"HEAD": true,
"DELETE": true,
"OPTIONS": true,
... |
package main
import "fmt"
func main() {
// Go is a statically typed programming language. This means that variables always have a specific type associated with it and cannot be changed.
// Syntax => var <name> <type>
var hello_str string
hello_str = "Hello World!"
fmt.Println(hello_str)
// Syntax => var <name... |
package accessibility
import (
"fmt"
"strconv"
"github.com/perthgophers/govhack/db"
)
type CongestionResult struct {
MeanValue float64 `db:"trafficrank"`
}
func Congestion(longitude, latitude float64) (int, error) {
score := []CongestionResult{}
longStr := strconv.FormatFloat(longitude, 'f', 6, 64)
latStr :... |
package main
//编译成LINUX下面的软件
//set GOOS=linux
//set GOARCH=amd64
//set CGO_ENABLED=0
//go install
//go build //1.8
//version
//bee v1.6.2
//beego v1.7.2
//go v1.6.2
import (
"openvpn/models"
_ "openvpn/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/session"
)
var ... |
package host
// Enable marks a profile as enable by uncommenting all hosts lines
// making the routing work again.
func Enable(dst, profile string) error {
h, err := getHostData(dst, profile)
if err != nil {
return err
}
if profile == "" {
for p := range h.profiles {
if p != "default" {
enableProfile(h... |
package user
import (
"fmt"
"github.com/gin-gonic/gin"
"lhc.go.game.center/model"
"net/http"
)
func GetList(c *gin.Context) {
page := model.NewPage()
if err:=c.ShouldBind(&page);err!=nil {
c.JSON(http.StatusOK,gin.H{"code":400,"msg":err.Error()})
return
}
fmt.Println(1)
fmt.Printf("%#v\n",page)
fmt.Pri... |
package launcher_test
import (
"context"
"math/rand"
"sync"
"testing"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/cdp"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/utils"
"github.com/ysmood/got"
)
func BenchmarkManager(b *testing.B) {
const concurrent = 30 // how many browsers wil... |
package dbModel
//
// defines your Database Models at here.
// reference: https://github.com/oceanho/gw/wiki/Scaffold-Guides#3-dbmodelxxgo
//
|
package generator
// TODO refactor to reuse common code
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/brainicorn/skelp/skelplate"
"github.com/brainicorn/skelp/skelputil"
)
var (
readmeFmtRepo = "README.md"
projectFmtRepo = "%s.md"
packageFmtRepo = "%s/%s.go"
projectNam... |
package utils
import (
"bytes"
"net/url"
"sort"
)
// KeySet 得到map的key集合
func KeySet(dict map[string]string) []string {
s := make([]string, 0, len(dict))
for k, _ := range dict {
s = append(s, k)
}
return s
}
// BuildQuery 建立带参数URL
func BuildQuery(dict map[string]string) (val url.Values) {
val = url.Value... |
package album
import (
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
"gopkg.in/matryer/respond.v1"
"github.com/gorilla/mux"
"github.com/dgrijalva/jwt-go"
// "github.com/gorilla/context"
)
//Controller ...
type Controller struct {
Repository Repository
}
// Index GET /
func (c *Controller) ... |
package database
import (
"ambassador/src/models"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var DB *gorm.DB
func Connect() {
var err error
dsn := "root:root@tcp(db:3306)/ambassador?charset=utf8mb4&parseTime=True&loc=Local"
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("Could no... |
package shell
import (
"encoding/json"
"errors"
"sync"
"time"
)
// WindowEventCallback - function signature for window callbacks.
type WindowEventCallback func([]byte)
// WindowOnCloseCallback - function called when window is closed.
type WindowOnCloseCallback func()
// Window handle to an electron window.
type... |
package db
import (
"gopkg.in/mgo.v2"
"log"
"os"
"github.com/antholord/poe-ML-indexer/api"
)
var dbString = os.Getenv("db")
type DB struct {
Session *mgo.Session
ScTempColl *mgo.Collection
}
func Connect() *DB{
if (dbString == ""){//dbString = "mongodb://test:test@ds123371.mlab.com:23371/heroku_lnc7sl64"
d... |
package db
import (
"github.com/RainerGevers/tasker/db/migrations"
"github.com/RainerGevers/tasker/models"
"gorm.io/gorm"
"log"
)
func RunMigrations(db *gorm.DB) {
_ = db.AutoMigrate(&models.Version{}, &models.User{})
var versions []models.Version
dbVersions := db.Select("version").Find(&versions)
if dbVersio... |
package main
import (
"bytes"
"context"
"errors"
"fmt"
blocks "github.com/ipfs/go-block-format"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/multicodec"
"github.com/ipld/go-ipld-prime/node/ba... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.