text stringlengths 11 4.05M |
|---|
package errors
const (
ZapUserCreateError = "error creating user"
ZapUserFetchError = "error fetching user"
ZapUserUpdateError = "error updating user"
ZapUserDeleteError = "error deleting user"
)
|
/*
* Copyright 2017 - 2019 KB Kontrakt LLC - 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 require... |
package main
import (
"encoding/hex"
"io"
"net"
"os"
"go.uber.org/zap"
cli "gopkg.in/urfave/cli.v2"
"github.com/rssllyn/go-raknet"
)
var Logger *zap.Logger
func init() {
Logger, _ = zap.NewDevelopment()
}
func main() {
app := &cli.App{
Name: "raknet test server",
Flags: []cli.Flag{
&cli.StringFlag... |
package lapdata_test
import (
"testing"
"github.com/matryer/is"
"go.jlucktay.dev/golang-workbench/jam-gp/lapdata"
)
func loadEventData(t *testing.T) *lapdata.Event {
is := is.New(t)
is.Helper()
e, err := lapdata.NewEvent()
is.NoErr(err)
is.True(e != nil)
return e
}
func TestNewEvent(t *testing.T) {
t.P... |
// go_05
package main
import (
"fmt"
"math"
)
/*go支持匿名函数,可以作为闭包,是一个内联语句或表达式
可以直接使用函数内的变量,不必声明*/
func getSequence() func() int {
index := 0
return func() int {
index += 1
return index
}
}
type Circle struct {//定义结构体
radius float64
}
func main() {
var a_var int = 100
var b_... |
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
type SpaceX []struct {
CapsuleSerial string `json:"capsule_serial"`
CapsuleID string `json:"capsule_id"`
Status string `json:"status"`
OriginalLaunch time.Time `json:"original_launch"`
OriginalLaunch... |
package main
import (
"flag"
"fmt"
"github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/server"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"syscall"
)
var configFile = flag.String("config", "", "ledisdb config file")
var addr = flag.String("addr", "", "ledisdb listen ad... |
package main
func main() {
a := [...]int{
1, 2,
}
p := &a
p[1] += 10
println(a[1])
}
|
package sys
import (
"fmt"
"strconv"
"strings"
)
func KillProcessByCmdline(cmdline string) error {
cmdline = strings.TrimSpace(cmdline)
if cmdline == "" {
return fmt.Errorf("cmdline is blank")
}
pids := PidsByCmdline(cmdline)
for i := 0; i < len(pids); i++ {
out, err := CmdOutTrim("kill", "-9", strconv.I... |
package openshift
import (
"context"
configv1 "github.com/openshift/api/config/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
func NewClusterOperator(name string) *ClusterOperator {
co := &ClusterOperator{ClusterOperator: &configv1.ClusterOperator{}}
co.SetName(name)
return co
}
type ClusterOperator s... |
package mpnifcloudrdb
import (
"errors"
"flag"
"log"
"strconv"
"strings"
"sync"
"time"
"github.com/alice02/nifcloud-sdk-go/nifcloud"
"github.com/alice02/nifcloud-sdk-go/nifcloud/credentials"
"github.com/alice02/nifcloud-sdk-go/nifcloud/session"
"github.com/alice02/nifcloud-sdk-go/service/rdb"
mp "github.c... |
package generators
import (
"github.com/almerlucke/kallos"
)
// Combinator combines generators in a single generator
type Combinator struct {
Generators []kallos.Generator
}
// NewCombinator returns a new combinator
func NewCombinator(gens ...kallos.Generator) *Combinator {
return &Combinator{
Generators: gens,... |
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
var printChar chan int
func prinNums() {
defer wg.Done()
for i := 0; i < 2; i++ {
fmt.Println("prinNums", i)
printChar <- 1111
fmt.Println("printnum", <-printChar)
}
}
func printChars() {
defer wg.Done()
for i := 0; i < 2; i++ {
fmt.Println("... |
package main
// contains the code for logging to the android syslog
// borrowed from go.mobile/app
/*
#cgo LDFLAGS: -llog
#include <android/log.h>
#include <string.h>
*/
import "C"
import (
"fmt"
"log"
"unsafe"
)
type infoWriter struct{}
var (
ctagLog = C.CString("SensuClient")
)
func (infoWriter) Write(p []by... |
package main
import (
"fmt"
"log"
"os"
homedir "github.com/mitchellh/go-homedir"
)
func main() {
if len(os.Args) > 2 {
fmt.Printf("Usage: command <filename>\n")
os.Exit(1)
}
path, err := homedir.Expand(os.Args[1])
if err != nil {
log.Fatal(err)
}
fmt.Println(path)
path, err = homedir.Dir()
if err... |
package mysqlenv
import "testing"
func TestBuildMySQLDSN(t *testing.T) {
t.Run("NoPass", func(t *testing.T) {
dsn := DSN("root", "", "127.0.0.1:3306", "stratex")
if dsn != "root@(127.0.0.1:3306)/stratex?parseTime=true" {
t.Errorf("DSN == %v ", dsn)
}
})
t.Run("Pass", func(t *testing.T) {
dsn := DSN("r... |
package main
import (
"bufio"
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
)
func main() {
file, err := os.Open("../input")
if err != nil {
log.Fatalln("Cannot open file", err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
var feet int64
for scanner.Scan() {
feet += howMuchRibbon(scanner.T... |
package main
var test int
const (
mutexLocked = 1<<iota
mutexLocked2
)
func main() {
mm := make(map[string]string,111111111111121)
mm["2"]="2"
//fmt.Println(mm)
//for i:= 0; i < 100000; i++ {
// mm[i]=i
//}
//test1()
//test2()
//test3(&mm)
}
//func test1() *int{
// aa := 0
// return &aa
//}
//func te... |
package main
import (
_ "archive/zip"
format "fmt"
)
func main() {
format.Println("test")
}
|
package main
import (
"bufio"
"fmt"
"net"
"os"
"strings"
)
func main() {
fmt.Println("Launching server...")
// listen on all interfaces
ln, _ := net.Listen("tcp", ":8085")
// accept connection on port
conn, _ := ln.Accept()
fmt.Println("Server launched!")
go messageListener(conn)
messegeSender(conn)... |
package main
import (
"github.com/mailgun/cli"
)
func NewUpstreamCommand() cli.Command {
return cli.Command{
Name: "upstream",
Flags: flags(),
Usage: "Operations with vulcan upstreams",
}
}
func NewUpstreamSubcommands() []cli.Command {
return []cli.Command{
{
Name: "add",
Usage: "Add a new upst... |
package wordmaker
import (
"bytes"
"fmt"
R "github.com/jmcvetta/randutil"
)
func Parse(name string, input []string, dropoff float64) (*Config, error) {
cfg := NewConfig(name)
for _, line := range input {
_, items := Lex(name, line)
header := <-items
switch header.typ {
case itemClass:
if err := cfg.Ad... |
package user
import (
"database/sql/driver"
"github.com/jinzhu/gorm"
"github.com/charlesfan/go-api/repository"
)
type UUID string
func (u UUID) Value() (driver.Value, error) { return string(u), nil }
type User struct {
UUID UUID `gorm:"column:uuid;unique;type:uuid;primary_key"`
Email string `gorm:"c... |
// Copyright (C) 2019. Vaultex, Inc - All rights reserved.
//
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
//
// Written by The Vaultex Engineers <engineers@vaultex.net>
package realip
import (
"net"
"net/http"
"strings"
)
var cidrs []*net.IPNet
fu... |
package target
type VMWareTargetOptions struct {
Filename string `json:"filename"`
Host string `json:"host"`
Username string `json:"username"`
Password string `json:"password"`
Datacenter string `json:"datacenter"`
Cluster string `json:"cluster"`
Datastore string `json:"datastore"`
}
func (VMWa... |
package main
import (
"testing"
"github.com/corymurphy/adventofcode/shared"
)
func Test_Part1(t *testing.T) {
expected := -3
input := shared.ReadInput("input_test")
actual := part1(input)
shared.AssertEqual(t, expected, actual)
}
func Test_Part2(t *testing.T) {
expected := 5
input := []string{"()())"}
ac... |
package routers
import "Go-Websocket/servers/websocket"
func WebsocketInit() {
websocket.Register("addGroup", websocket.AddGroupController)
websocket.Register("heartbeat", websocket.HeartbeatController)
}
|
/*
* Copyright (c) 2021 - present Kurtosis Technologies LLC.
* All Rights Reserved.
*/
package files_artifact_mounting_test
import (
"github.com/kurtosis-tech/kurtosis-go/lib/networks"
"github.com/kurtosis-tech/kurtosis-go/lib/services"
"github.com/kurtosis-tech/kurtosis-go/lib/testsuite"
"github.com/kurtosis-... |
package hooks
import (
"database/sql"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/square/p2/pkg/logging"
)
func initSQLiteAuditLogger(t *testing.T) (*SQLiteAuditLogger, string, *sql.DB) {
tempDir, err := ioutil.TempDir("", "hooks_audit_log")
if err != nil {
t.Fatalf("Could not set up for hook au... |
package appbase
import (
"testing"
"os"
"github.com/urfave/cli"
"fmt"
)
func Test_flags(T *testing.T) {
app := create()
app.Action = act
app.Commands = []cli.Command{
versionCommand,
}
fg := NewFlags("TEST")
fg.Add(&cli.BoolFlag{
Name: "booltest",
Usage: "this is booltest",
})
fg.Add(&cli.Strin... |
package sort
// InsertSort ..
func InsertSort(data []int) {
var len int = len(data)
for i := 1; i < len; i++ {
var tmp int = data[i]
j := i - 1
for ; j >= 0; j-- {
var aim int = data[j]
if aim > tmp {
data[j+1] = data[j]
} else {
break
}
}
data[j+1] = tmp
}
}
// BubbleSort ..
func Bub... |
// Package hash 实现hash数据结构相关算法
package hash
import (
"github.com/carney520/go-algorithm/data-structure/list"
)
// Match 用于比较两个键是否相等
type Match func(a, b interface{}) bool
// Hasher 表示一个可求hash的接口
// 所有键必须实现这个接口
type Hasher interface {
hash() int
}
// Tabler 表示不同类型hash表需要实现的方法
type Tabler interface {
Get(key Hashe... |
/*
Description
In a big and rich on natural resources country, the government started a campaign to control deforestation. In fact the government is not too interested in how many trees get fallen, but rather how effectively the wood is utilized. So a law was passed which requires every logging company to pay amount ... |
package quic
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Client Multiplexer", func() {
It("adds a new packet conn ", func() {
conn := newMockPacketConn()
_, err := getMultiplexer().AddConn(conn, 8)
Expect(err).ToNot(HaveOccurred())
})
It("errors when adding an existi... |
package main
import (
"testing"
"time"
)
func BenchmarkSleepWith(b *testing.B) {
b.StopTimer()
// 数据准备阶段
time.Sleep(time.Second * 2)
b.StartTimer()
// 实测函数
SleepWith()
} |
package middle
// GameFinderVFSList performs BrowserVFSList and converts the results to GameLocations.
func GameFinderVFSList(vfsPath string) []GameLocation {
vfsEntries := []GameLocation{}
for _, fi := range BrowserVFSList(vfsPath) {
if fi.Dir {
cgl := CheckGameLocation(fi.Location)
cgl.Drive = fi.Drive
... |
package acl
import (
"encoding/json"
"fmt"
"net/url"
"strings"
api "github.com/uhppoted/uhppoted-lib/acl"
"github.com/uhppoted/uhppoted-lib/uhppoted"
"github.com/uhppoted/uhppoted-mqtt/common"
)
func (a *ACL) Upload(impl uhppoted.IUHPPOTED, request []byte) (interface{}, error) {
body := struct {
URL *strin... |
package main
import (
"fmt"
"os"
"sync"
"os/exec"
"context"
"log"
"bufio"
"strings"
"net/http"
"io/ioutil"
"path/filepath"
"encoding/json"
)
type Playlist struct {
Name string `mapstructure:"name" bson:"name" json:"name"`
}
type Track struct {
EId string `mapstructure:"eId" bso... |
package chip8
import "testing"
func TestBitExtraction(t *testing.T) {
c := NewChip8(nil, validTestROM)
opcode := uint16(0x9F4D)
nnn, n, x, y, kk := c.extractReferenceBits(opcode)
if nnn != 0xF4D {
t.Errorf("nnn was not parsed correctly: %v", nnn)
}
if n != 0xD {
t.Errorf("n was not parsed correctly: %v",... |
package filters
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/neuronlabs/neuron-core/query"
)
// TestBasicSQLizer test the basic sqlizer functions
func TestBasicSQLizer(t *testing.T) {
t.Run("Single", func(t *testing.T) {
s := getScope(t)
fv := &q... |
/*
This file holds types and functions supporting command-related activity in DVID.
These Command types bundle operation specification and data payloads for use in
RPC and HTTP APIs.
*/
package dvid
import (
"fmt"
"strings"
)
// Keys for setting various arguments within the command line via "key=value" strings.... |
package formats
import (
"context"
"fmt"
"os"
"github.com/olivere/elastic/v7"
"gopkg.in/cheggaaa/pb.v2"
)
type JSON struct {
Outfile *os.File
ProgessBar *pb.ProgressBar
}
func (j JSON) Run(ctx context.Context, hits <-chan *elastic.SearchHit) error {
for hit := range hits {
fmt.Fprintln(j.Outfile, strin... |
package vminterface
import (
com "github.com/cryptokass/levm/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/ethdb"
)
// NewStateDB - Create a new StateDB using levelDB instead of RAM
func ... |
// Copyright (c) 2014-2017 The btcsuite developers
// Copyright (c) 2015 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package waddrmgr
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"time"
"github.com/btcsuite/btcd/... |
package conclusion
import (
"sort"
"testing"
"github.com/stretchr/testify/require"
)
func TestTreeNode(t *testing.T) {
n := &TreeNode{
Val: 1,
Right: &TreeNode{
Val: 3,
Left: &TreeNode{
Val: 2,
},
},
}
assert := require.New(t)
assert.Equal("[1,null,3,2]", n.String())
}
func Test_generateT... |
package usage_test
import (
"fmt"
"io/ioutil"
"time"
_ "github.com/manishrjain/gocrud/drivers/leveldb"
_ "github.com/manishrjain/gocrud/drivers/memsearch"
"github.com/manishrjain/gocrud/indexer"
"github.com/manishrjain/gocrud/req"
"github.com/manishrjain/gocrud/search"
"github.com/manishrjain/gocrud/store"
... |
package util
import (
"time"
log "github.com/Sirupsen/logrus"
)
type Scheduler struct {
task Task
interval time.Duration
quit chan int
}
type Task func() error
func NewScheduler(t Task, interval time.Duration) *Scheduler {
return &Scheduler{task: t, interval: interval, quit: make(chan int)}
}
func (... |
package api
import (
"WAF/middlewares"
"WAF/models"
"WAF/utils"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
)
// @Tags User
// @Summary 用户登录
// accept json
// produce json
// @Param name query string true "用户名"
// @Param passwd query string true "密码... |
package openvswitch
import (
"testing"
"github.com/joatmon08/ovs_exporter/utils"
"encoding/json"
"reflect"
)
func TestParseStatisticsFromData(t *testing.T) {
var test []map[string]interface{}
expected := map[string]float64{
"collisions": 0,
"rx_bytes": 1026,
"rx_crc_err": 0,
"rx_dropped": 0,
"rx_error... |
/*
Odd prime numbers are either in the form of 4k+1 or 4k+3 where k is a non-negative integer. If we divide the set of odd prime numbers into two such groups like this:
4k+3 | 3 7 11 19 23 31 43 47 59 67 71
|
4k+1 | 5 13 17 29 37 41 ... |
package main
import (
"github.com/ziutek/mymysql/autorc"
_ "github.com/ziutek/mymysql/native"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"
"unicode"
)
var (
ins []*Input
logFileName string
smsd *SMSd
)
func parseList(l string) []string {
var a []string
for {
n := strings.IndexFunc... |
package invoker
import (
"context"
v1 "github.com/mee6aas/zeep/pkg/api/invoker/v1"
)
// Invoke request to invoke the specified activity name with the arg.
func Invoke(ctx context.Context, actName string, arg string) (rst string, e error) {
res, e := client.Invoke(ctx, &v1.InvokeRequest{
ActName: actName,
Arg:... |
package info
import (
"fmt"
"io/ioutil"
"github.com/bwmarrin/discordgo"
)
var fileList map[string]bool
var fileListString string
func RefreshFileList() {
files, err := ioutil.ReadDir("./config/messages")
if err != nil {
fmt.Println(err)
return
}
fileList = make(map[string]bool)
fileListString = "**Lis... |
package main
import (
"flysnow/utils"
"fmt"
"log"
"net/http"
)
func main() {
utils.FSConfig.SetMod("sys")
if utils.FSConfig.IntDefault("web", 0) == 1 {
port := utils.FSConfig.StringDefault("web.port", "22259")
http.HandleFunc("/", defaultHandler)
http.HandleFunc("/configs", configHandler)
log.Fatal(http... |
// write a go program that finds the average of command line float values
|
package main
// List here all required micro plugins
// Go here: https://github.com/micro/go-plugins
import (
_ "github.com/micro/go-plugins/registry/consul/v2"
)
|
/*
* @lc app=leetcode.cn id=2 lang=golang
*
* [2] 两数相加
*/
package solution
// @lc code=start
func addTwoNumbers(l1 *ListNode, l2 *ListNode) (ans *ListNode) {
p, p1, p2, carry := &ListNode{}, l1, l2, 0
ans = new(ListNode)
p.Next = ans
for p1 != nil || p2 != nil {
var n1, n2 int
if p1 != nil {
n1, p1 = p... |
// Go support for Protocol Buffers RPC which compatiable with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket
//
// Copyright 2002-2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// Yo... |
package main
import (
"flag"
"net/http"
"time"
klog "k8s.io/klog/v2"
)
func main() {
// initialize klog
klog.InitFlags(nil)
flag.Parse()
// upgrade limits to the maximum possible, the proxy use a lot of files...
setLimits()
// disable proxy configuration in env variables
noProxyDefaultTransport := http... |
/*
Anthony is participating in a programming contest today! He’s excellent at algorithms; he can design and implement the solution to even the hardest problems in the programming contest in minutes.
Unfortunately, parsing inputs is his greatest weakness. Specifically, he really struggles with problems which require hi... |
package rtrserver
import (
"bytes"
"encoding/binary"
"errors"
"time"
"github.com/cpusoft/goutil/belogs"
"github.com/cpusoft/goutil/iputil"
"github.com/cpusoft/goutil/jsonutil"
model "rpstir2-model"
)
func ParseToResetQuery(buf *bytes.Reader, protocolVersion uint8) (rtrPduModel RtrPduModel, err error) {
var ... |
package main
import (
"github.com/gin-gonic/gin"
"github.com/jimmiepr/Gin-TDD/internal/service"
)
func main() {
r := gin.Default()
v1 := r.Group("/api/v1")
{
v1.GET("/getdata", service.GetData)
}
r.Run(":3000")
}
|
package main
import (
"C"
"encoding/json"
"fmt"
. "github.com/matiassequeira/lorawan"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
// TEST MESSAGES
// {"mhdr":{"mType":"JoinRequest","major":"LoRaWANR1"},"macPayload":{"joinEUI":"55d239ac716f234d","devEUI":"b827eb891... |
package etcd
import (
"testing"
"time"
)
func TestJoinNotifiers(t *testing.T) {
t.Parallel()
a := make(chan struct{})
b := make(chan struct{})
c := joinNotifiers(a, b)
timeout := time.Tick(30 * time.Second)
select {
case <-c:
case <-timeout:
t.FailNow()
}
a <- struct{}{}
select {
case <-c:
case ... |
package server
import (
"io/ioutil"
"net/http"
"github.com/ItsJimi/casa/logger"
"github.com/jmoiron/sqlx"
)
// User structure in database
type User struct {
ID string `db:"id" json:"id"`
Firstname string `db:"firstname" json:"firstname"`
Lastname string `db:"lastname" json:"lastname"`
Email strin... |
package bardo
import (
"strings"
)
// GetTables ...
// Get an array of all tables in the database
func (db *Database) getAllTables() ([]string, error) {
var tables []struct {
Name string `db:"table_name"`
}
err := db.Select(&tables, `
SELECT table_name
FROM information_schema.tables
WHERE table_schema... |
package transport
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"github.com/gorilla/websocket"
"log"
"strings"
"errors"
)
// The Dialer handles connecting to a server and creating a connection.
type Dialer struct {
TLSConfig *tls.Config
RequestHeader http.Header
DefaultTCPPort string
Defau... |
// Copyright 2014 Marc-Antoine Ruel. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package main
import (
"fmt"
"github.com/maruel/subcommands"
)
var cmdAskApple = &subcommands.Command{
UsageLine: "apple <options>",
Sho... |
package controller
import "github.com/therecipe/qt/core"
type topController struct {
core.QObject
}
|
package sshmux
import (
"fmt"
"io"
"net"
"sync"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
func proxy(reqs1, reqs2 <-chan *ssh.Request, channel1, channel2 ssh.Channel) {
var closer sync.Once
closeFunc := func() {
channel1.Close()
channel2.Close()
}
defer closer.Do(closeFunc)
closerC... |
package main
import "go_learn/day06/mylogger"
func main() {
mylogger.NewLog("debug").Debug("这是一条debug日志")
}
|
package main
import (
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/web"
)
func main() {
//consul服务注册
ginRouter := gin.Default()
data := make([]interface{}, 0)
ginRouter.Handle("GET", "/", func(context *gin.Context) {
context.JSON(200, gin.H{
"data": data,
})
})
server := web.NewService(
web... |
package main
import (
"github.com/Eric-WangHaitao/Go-0712/Week04/internal"
"log"
)
func main() {
log.Fatal(internal.NewApp().Run())
}
|
/*
* @lc app=leetcode.cn id=95 lang=golang
*
* [95] 不同的二叉搜索树 II
*/
package solution
// @lc code=start
type anchor struct {
start, end int
}
func generateTrees(n int) []*TreeNode {
max := func(x, y int) int {
if x > y {
return x
}
return y
}
// Calculate the number of binary search trees can be gene... |
package hpke
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSeal(t *testing.T) {
k1, err := GeneratePrivateKey()
require.NoError(t, err)
k2, err := GeneratePrivateKey()
require.NoError(t, err)
sealed, err := Seal(k1, k2.PublicKey(), []byte("HELLO WOR... |
package main
import (
"encoding/hex"
"flag"
"fmt"
"log"
"dfnpf/examples/iniths"
)
func main() {
flag.Parse()
if len(flag.Args()) < 4 || len(flag.Args()) > 11 {
log.Fatalln("Please provide Noise Protocol name, initiator's static and ephemeral keys,",
"\n responder's static and ephemeral keys, remote key... |
package models
type ResultChallenge struct {
Time int64 `json:"time"`
HighScore int64 `json:"high_score" bson:"high_score"`
Combo int `json:"combo"`
BestCombo int `json:"best_combo" bson:"best_combo"`
} |
package main
import (
"fmt"
"time"
)
func badEcho(in <-chan string) {
// invalid operation: in <- "bad bad",
// send to receive-only type <-chan string
in <- "bad bad"
}
func testEcho(in <-chan string, out chan<- string) {
inStr := <-in
fmt.Println("routine rx:", inStr)
out <- inStr
}
func main() {
inChan ... |
package main
import (
"context"
"fmt"
"github.com/serverless/better/lib/model"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider/cognitoidentityprovideriface"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/serv... |
package main
import "fmt"
func main() {
fmt.Print("Same")
fmt.Print("Line. ")
fmt.Println("New")
fmt.Println("Line")
x := 3.141516
xs := fmt.Sprint(x)
fmt.Println("X = " + xs)
fmt.Println("X = ", x)
fmt.Printf("X = %.2f.", x)
a := 1
b := false
c := "opa"
fmt.Printf("\n%d %t %s", a, b, c)
}
|
package main
import (
"fmt"
"math/cmplx"
)
var (
ToBe bool = false
MaxInt uint64 = 1<<64 - 1
z complex128 = cmplx.Sqrt(-5 + 12i)
)
func main() {
const f = "%T(%v)\n"
fmt.Printf(f, ToBe, ToBe)
fmt.Printf(f, MaxInt, MaxInt)
fmt.Printf(f, z, z)
// bool(false)
// uint64(18446... |
package controllers
import (
"github.com/revel/revel"
)
type ProjectController struct {
*revel.Controller
}
func (c * ProjectController) NewProject() revel.Result{
result := RenderMap(200, "ok")
return c.RenderJson(result)
}
|
package storage
var taskSchema = `
CREATE TABLE tasks (
id int8 PRIMARY KEY,
created_at timestampz NOT NULL,
name text,
priority int4 NOT NULL,
start timestampz,
duration string
);
`
|
package main
import (
"fmt"
)
func main() {
fmt.Println(shortestPathBinaryMatrix([][]int{
{0, 0, 0},
{1, 1, 0},
{1, 1, 1},
}))
// test63
fmt.Println(14 == shortestPathBinaryMatrix([][]int{
{0, 1, 0, 0, 0, 0},
{0, 1, 0, 1, 1, 0},
{0, 1, 1, 0, 1, 0},
{0, 0, 0, 0, 1, 0},
{1, 1, 1, 1, 1, 0},
{1, ... |
package 模拟
func findDiagonalOrder(matrix [][]int) []int {
if len(matrix) == 0 {
return []int{}
}
m, n := len(matrix), len(matrix[0])
ans := make([]int, 0, n*m)
curX, curY, indexSum := 0, 0, 0 // indexSum = curX + curY,在同一对角线上遍历时indexSum是不变的
// n + m - 1: 这是最后一条对角线的索引和
for indexSum != n+m-1 {
if indexSum%2 =... |
package main
import (
"go-kemas/config"
"go-kemas/models"
"go-kemas/routes"
)
func main() {
db := config.SetupDB()
db.AutoMigrate(&models.Task{})
db.AutoMigrate(&models.Program{})
db.AutoMigrate(&models.Admin{})
db.AutoMigrate(&models.User{})
r := routes.SetupRoutes(db)
r.Run()
} |
package main
import (
"fmt"
)
// AppName: GoSpider
// Auther : Sven Liu
// Gmail : whoamsven@gmail.com
func main() {
fmt.Println(" hell world ! My name is GoSpider !")
}
|
package fsutils
import (
"io/ioutil"
"path"
)
type fsutils struct{}
func New() *fsutils {
return &fsutils{}
}
func (fsu *fsutils) GetFilesList(dir string) ([]string, error) {
files, err := ioutil.ReadDir(dir)
var fileList []string
if err == nil {
for _, file := range files {
fileList = append(fileList, f... |
package main
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"sync"
"github.com/hdlopez/go-talks/2019/gopherconuk/examples/context"
)
// START 1 OMIT
// Private, available only from within the package
type header struct {
}
// Public, available from other packages
func Export() {
}
// Private, available only ... |
/*
Go Language Raspberry Pi Interface
(c) Copyright David Thorpe 2019
All Rights Reserved
Documentation http://djthorpe.github.io/gopi/
For Licensing and Usage information, please see LICENSE.md
*/
package sensordb
import (
"fmt"
"strconv"
"strings"
"time"
// Frameworks
gopi "github.com/djthorpe/gopi"... |
package main
// Display the character and string repeatedly 5 times.
func main() {
display1 := NewCharDisplay("H") // Create an instance of the CharDisplay
display2 := NewStringDisplay("Hello world.") // Create an instance of the StringDisplay
display3 := NewStringDisplay("Nice to meet you."... |
package main
import "fmt"
func main() {
type user struct {
name string
age byte
}
m := map[int]user{
1: {"Tom", 19},
}
u := m[1]
u.age += 1
m[1] = u
fmt.Println(m[1])
m2 := map[int]*user{
1: &user{"Jack", 20},
}
m2[1].age++
fmt.Println(*m2[1])
}
|
package main
//语言运算
func testLanguage (){
}
//条件语句
func testCondition(){
}
func main() {
}
|
package models
import (
"github.com/jinzhu/gorm"
"golang.org/x/crypto/bcrypt"
"errors"
log "github.com/sirupsen/logrus"
)
type User struct {
gorm.Model
Name string `json:"name"`
Email string `gorm:"type:varchar(100);unique_index"`
Password string `json:"password"`
}
type userDTO struct {
Name string `json:... |
package main
import (
DB "LivingPointAPI/database/database"
"context"
"log"
"time"
"google.golang.org/grpc"
)
func main() {
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
if err != nil {
log.Fatal("did not connect: ", err)
}
defer conn.Close()
c := DB.NewDatabaseClient(conn)
ctx, cancel... |
package main
import (
"crypto/ecdsa"
"encoding/hex"
"flag"
"fmt"
"math"
"os"
"regexp"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/crypto"
)
// The following code takes inspiration from and generalizes the code at https://github.com/chrsow/geth-vanitygen
// Command line flag parsing
type stringsFl... |
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
// 使用GET方法进行Request请求
req, err := http.NewRequest("GET", "https://www.baidu.com", nil)
if err != nil {
log.Fatalf("could not create request: %v", err)
}
// 使用http创建一个client
client := http.DefaultClient
// 执行Request请求,并得到response
res, err := cli... |
package configuration
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/authelia/authelia/v4/internal/utils"
)
func TestShouldHaveSameChecksumForBothTemplates(t *testing.T) {
sumRoot, err := utils.HashSHA256FromPath("../../config.template.yml")
assert.NoError(t, err)
sumInternal, err := uti... |
/*
Copyright 2021 The KubeVela 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, softw... |
package module
/**
* 底层redis 连接池
* @author guojun-s@360.cn
*
*/
import (
"github.com/garyburd/redigo/redis"
"time"
)
const (
PROTOCOL = "tcp" //connection protocol
)
var (
MaxIdle int = 100
MaxActive int = 1000
IdleTimeout time.Duration = time.Duration(28 * time.Second)
)
//
//v... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.