text stringlengths 11 4.05M |
|---|
package bitswap
import (
"context"
"encoding/json"
"io/ioutil"
"math/rand"
"sync"
"testing"
"time"
"gx/ipfs/QmYJ48z7NEzo3u2yCvUvNtBQ7wJWd5dX2nxxc7FeA6nHq1/go-bitswap/testutil"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
mockrouting "gx/ipfs/QmRJvdmKJoDcQEhhTt5NYXJPQFnJYPo1kfapxtjZLf... |
package testutil_test
import (
"github.com/APTrust/exchange/util/fileutil"
"github.com/APTrust/exchange/util/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"path/filepath"
"testing"
)
func TestFindIngestManifestInLog(t *testing.T) {
pathToLogFile, _ := fileutil.RelativeToA... |
package identity
// SHA256ID 是一个 256-bits 长度的HID
type SHA256ID struct {
data [32]byte
}
|
package main
import (
"context"
"github.com/InVisionApp/go-health/checkers"
"github.com/alexliesenfeld/health"
"log"
"net/http"
"net/url"
"time"
)
func main() {
// Create checkers as usual.
googleURL, err := url.Parse("https://www.google.com")
if err != nil {
log.Fatalln(err)
}
check, err := checkers.N... |
package main
import (
"log"
"time"
)
var s = "seven"
//
type User struct {
FirstName string
LastName string
PhoneNumber string
Age int
BirthDate time.Time
}
func main() {
user := User{
FirstName: "Sean",
LastName: "Tseng",
PhoneNumber: "0910313342",
}
log.Println(user.FirstName,... |
package main
import (
"fmt"
"time"
)
const (
SEC = 1 * 1e9
)
type Mtex struct {
channel chan int
customer_in_queue *bool
}
func createMtex() Mtex {
var mutex = make(chan int, 1)
var customer_in_queue bool = false
return Mtex{mutex, &customer_in_queue}
}
func lockM(mutex Mtex, isBarber bool) bool ... |
// package p_test is testing for p
// which p is a php adapter
package p_test
import (
"fmt"
"sync"
"testing"
"github.com/Kretech/xgo/p"
"github.com/Kretech/xgo/test"
)
func TestAll(t *testing.T) {
cas := test.TR(t)
// cas.Add(testArgsName)
// cas.Add(testConcurrenceArgsName)
// cas.Add(testCompact)
// ... |
package kstest
import (
"math"
"sort"
"github.com/yash-ontic/morgoth"
"github.com/yash-ontic/morgoth/counter"
)
var confidenceMappings = []float64{
1.22,
1.36,
1.48,
1.63,
1.73,
1.95,
}
// Kolmogorov–Smirnov test.
// https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test
//
// The fingerprint is th... |
package sqlindo
import (
"fmt"
"testing"
)
// func TestGetConfigs(t *testing.T) {
// var db DB
// db.Driver = "postgres"
// //db.Host = "cfg.rede.tri.com.br"
// db.Host = "127.0.0.1"
// db.SSLMode = "disable"
// db.Port = "5432"
// db.Name = "pet3"
// db.User = "postgres"
// db.Password = ""
// db.Conne... |
package models
import (
"os"
"strings"
"github.com/dgrijalva/jwt-go"
u "github.com/hjoshi123/GORest/utils"
"github.com/jinzhu/gorm"
"golang.org/x/crypto/bcrypt"
)
// Token is a struct that will be encoded to JWT. jwt.StandardClaims is added to include
// details like expiry etc
type Token struct {
UserID uint... |
package gallery
import (
"testing"
. "github.com/bborbe/assert"
)
func TestCreateCollection(t *testing.T) {
var err error
collectionId := "collectionId123"
collectionName := "collectionName123"
collectionPrio := 23
collection := CreateCollection(collectionId, collectionName, collectionPrio)
err = AssertThat(... |
package mytest
import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"sync"
"testing"
"time"
)
func TestChannel(t *testing.T) {
testCh := make(chan int64)
go func() {
testCh <- 10
}()
fmt.Println("sent result")
fmt.Println(<-testCh)
}
func TestOnce(t *testing.T) {
var one sync.Once
var wg sync.WaitGr... |
package straw
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"sort"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
var _ StreamStore ... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//766. Toeplitz Matrix
//A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.
//Now given an M x N matrix, return... |
package oam
import "github.com/layer5io/meshkit/errors"
const (
ErrLoadingPathsetCode = "1004"
)
func ErrLoadingPathset(err error) error {
return errors.New(ErrLoadingPathsetCode, errors.Alert, []string{"Could not create a pathset for static component generation"}, []string{err.Error()}, []string{}, []string{})
}
|
package fakes
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
bmstemcell "github.com/cloudfoundry/bosh-micro-cli/stemcell"
bmtestutils "github.com/cloudfoundry/bosh-micro-cli/testutils"
)
type CreateInput struct {
StemcellManifest bmstemcell.Manifest
}
type createOutput struct {
cid bmstem... |
package shamir_test
import (
"math/rand"
"testing"
"time"
"github.com/renproject/secp256k1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/renproject/shamir"
. "github.com/renproject/shamir/shamirutil"
)
//
// Let n and k be given where n >= k. Then Shamir secret sharing with these
// p... |
package leetcode
import "fmt"
func largestTimeFromDigits(A []int) string {
cnt := make(map[int]int)
for _, v := range A {
cnt[v]++
}
for hr := 23; hr >= 0; hr-- {
if cnt[hr/10] > 0 && cnt[hr%10] > 0 {
if hr/10 == hr%10 && cnt[hr/10] == 1 {
continue
}
cnt[hr/10]--
cnt[hr%10]--
a, b := -1, -1... |
package main
import (
"runtime/debug"
"sync/atomic"
"sync"
"fmt"
"runtime"
)
func main() {
f := fmt.Println
// 禁用GC,并保证在main函数执行结束前恢复GC
defer debug.SetGCPercent(debug.SetGCPercent(-1))
var count int32
newFunc := func() interface{} {
return atomic.AddInt32(&count, 1)
}
pool := sync.Pool{New: newFunc}
... |
/*
(Easy): Checksums
Checksums are a tool that allow you to verify the integrity of data (useful for networking, security, error-correction, etc.). Though there are many different Checksum algorithms, the general usage is that you give raw-data to your algorithm of choice, and a block of data (usually smaller than t... |
package main
import (
_ "github.com/terraform-providers/terraform-provider-nutanix"
)
|
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.
// Package datadoghq contains datadoghq API versions.
//
// This file ensure... |
// Copyright 2016-2021, Pulumi Corporation.
//
// 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... |
package mutex_learn
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
func main() {
var count = 0
// 使用WaitGroup等待10个goroutine完成
var wg sync.WaitGroup
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
defer wg.Done()
// 对变量count执行10次加1
for j := 0; j < 100000; j++ {
count++
}
}()
}
// 等待10个gor... |
package bayarsetoran2
import (
"context"
"github.com/mirzaakhena/danarisan/application/apperror"
"github.com/mirzaakhena/danarisan/domain/entity"
"github.com/mirzaakhena/danarisan/domain/service"
"github.com/mirzaakhena/danarisan/domain/vo"
)
//go:generate mockery --dir port/ --name BayarSetoranOutport -output m... |
package main
import "fmt"
// 122. 买卖股票的最佳时机 II
// 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
// 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。
// 注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
// 提示:
// 1 <= prices.length <= 3 * 10 ^ 4
// 0 <= prices[i] <= 10 ^ 4
// https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-i... |
package compiler
type path struct {
nfaStateID int
}
|
package main
import (
"html/template"
"io"
"net/http"
"log"
"github.com/kazuhei/goweb-tutorial/application/settings"
"github.com/kazuhei/goweb-tutorial/domain/repository"
"github.com/labstack/echo"
)
func main() {
t := &Template{
templates: template.Must(template.ParseGlob("templates/*.html")),
}
e := e... |
package _113_Path_Sum_2
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func pathSum(root *TreeNode, sum int) [][]int {
ret := [][]int{}
cur := []int{}
pat... |
package main
import (
"fmt"
"sort"
"strconv"
"strings"
lane "gopkg.in/oleiade/lane.v1"
"github.com/jackytck/projecteuler/tools"
)
// Node represents a set of size n.
type Node struct {
set []int
}
func (n *Node) copy() Node {
s := make([]int, len(n.set))
copy(s, n.set)
return Node{s}
}
func (n *Node) ch... |
package leetcode
import "testing"
func TestMinDeletionSize(t *testing.T) {
if minDeletionSize([]string{"cba", "daf", "ghi"}) != 1 {
t.Fatal()
}
if minDeletionSize([]string{"a", "b"}) != 0 {
t.Fatal()
}
if minDeletionSize([]string{"zyx", "wuv", "tsr"}) != 3 {
t.Fatal()
}
}
|
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
package vela
import (
"fmt"
"github.com/go-vela/types/library"
)
// BuildService handles retrieving builds from
// the server methods of the Vela API.
type BuildService ... |
package sequence
import (
"math"
)
type SequenceStat struct {
Size int
Max float64
Min float64
Average float64
Stdev float64 // 样本标准差
Stdevp float64 // 总体标准差
}
func NewSequenceStat() *SequenceStat {
ret := &SequenceStat{}
ret.Clear()
return ret
}
func (stat *SequenceStat) Clear() {
stat.Max ... |
// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.
package restore
import (
"context"
"io"
"time"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
recovpb "github.com/pingcap/kvproto/pkg/recoverdatapb"
"github.com/pingcap/log"
"github.com/pingcap/tidb/br/pkg/common"
"github.com/pin... |
package mapper
import (
"database/sql"
"github.com/fatih/structs"
"github.com/xormplus/xorm"
entity "mix/test/entity/core/transaction"
"regexp"
"mix/test/utils/mysql"
)
func CreateHotWithdraw(session *xorm.Session, item *entity.HotWithdraw) (sql.Result, error) {
return session.SqlMapClient("CreateHotWithdraw"... |
/*!
*test.go version 4.0.0
*
*Copyright © 2021 All Rights Reserved.
*Author: Ryuto Otsubo
*
*Released under the MIT license.
*See https://opensource.org/licenses/MIT
*
*Git: https://github.com/OtsuboRyuto/LMS
*
*------------------- References --------------------
*
*https://qiita.com/chan-p/items/cf3e007b... |
package api
import ()
//CreateAccountReq 创建账户请求
type CreateAccountReq struct {
Account string
Password string
}
//CreateAccountResp 创建账户响应
type CreateAccountResp struct {
RespBase
}
//AccountReq 查询账户请求
type AccountReq struct {
Account string
}
//AccountResp 查询账户响应
type AccountResp struct {
RespBase
Name ... |
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/Jpserrat/hex-ddd-example/pkg/mongoclient"
"github.com/Jpserrat/hex-ddd-example/pkg/order/application/orderhandlers"
"github.com/Jpserrat/hex-ddd-example/pkg/order/domain/orderservice"
"github.com/Jpserrat/hex-ddd-example/pk... |
package blockchain
import (
"bytes"
"crypto/sha256"
"encoding/gob"
"fmt"
"github.com/alishoker/blockchinho/transaction"
"log"
"time"
)
type Block struct {
Header []byte
PreHeader []byte
TimeStamp int64
Transactions []*transaction.Transaction
Nonce int
}
func NewBlock(preHeader []byte, ... |
package stat
import (
"context"
"testing"
"time"
"github.com/pascaldekloe/sqltest"
)
func TestSwapsFromRuneLookup(t *testing.T) {
DBQuery = sqltest.NewTx(t).QueryContext
got, err := SwapsFromRuneLookup(context.Background(), testWindow)
if err != nil {
t.Fatal(err)
}
t.Logf("got %+v", got)
}
func TestSwap... |
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type Payload struct {
Profile Data
}
type Personal struct{
First_name string
Last_name string
Age int
Email string
}
type Data struct {
Info Personal
Languages Languages
}
type Languages map[string]int
func serveRest(w http.ResponseWriter, r *ht... |
package adapter
import (
"00-newapp-template/internal/pkg"
"00-newapp-template/pkg/acme"
)
type Unmarshal struct {
Config *pkg.Config
}
func NewUnmarshal(config *pkg.Config) (u Unmarshal) {
u.Config = config
return
}
func (u *Unmarshal) Service() (s acme.Service) {
s = acme.NewService(u.Config.Client.BaseURL,... |
package main
import (
"fmt"
"net/http"
)
func main() {
// HandleFunc registers the handler function for the given pattern
// in the DefaultServeMux.
// The documentation for ServeMux explains how patterns are matched.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
// Fprint uses a writer... |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package azurestack
import "time"
// DefaultARMOperationTimeout defines a default (permissive) ARM operation timeout
const DefaultARMOperationTimeout = 150 * time.Minute
|
package main
/*
* @lc app=leetcode.cn id=62 lang=golang
*
* [62] 不同路径
*/
// @lc code=start
func uniquePaths(m int, n int) int {
var result int
var dp [][]int = make([][]int, m)
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
if j == 0 {
dp[i] = make([]int, n)
}
if i == 0 || j == 0 {
dp[... |
// Copyright 2016 Alexander Bulimov. All rights reserved.
// Use of this source code is governed by a MIT license
// Utility to perform queries on PostgreSQL/MySQL database and warn on query result
package main
import (
"flag"
"fmt"
"os"
"github.com/abulimov/db-checker/lib"
"github.com/fractalcat/nagiosplugin"... |
// 使用普通的dial链接服务器
package main
import (
"bufio"
"fmt"
"net"
"os"
"project/errorDispose"
"strings"
)
func main() {
// 链接到服务器
connDial, error := net.Dial("tcp", "127.0.0.1:7777")
defer func() {
_ = connDial.Close()
fmt.Println("链接关闭")
}()
errorDispose.ErrorPrint(error, "链接错误")
textBufio := bufio.NewRead... |
package dao
import (
"log"
. "github.com/ubiq/spectrum-api/models"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type SpectrumDAO struct {
Server string
Database string
}
var db *mgo.Database
const (
BLOCKS = "blocks"
TXNS = "transactions"
UNCLES = "uncles"
TRANSFERS = "tokentransfers"
REO... |
package domain
const (
FarmTypeOrganic = "organic"
FarmTypeHydroponic = "hydroponic"
FarmTypeAquaponic = "aquaponic"
FarmTypeMushroom = "mushroom"
FarmTypeLiveStock = "livestock"
FarmTypeFisheries = "fisheries"
FarmTypePermaculture = "permaculture"
)
type FarmType struct {
Code string `jso... |
package main
import (
"fmt"
"strconv"
"strings"
)
var ones = []string { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }
var tens = []string { "", "ten", "twenty", "thirty... |
package models
type Techbook struct {
Id int `db:"id"`
CurrentUrl string `db:"current_url"`
}
|
/*
The dragon curve sequence (or the regular paper folding sequence) is a binary sequence. a(n) is given by negation of the bit left of the least significant 1 of n. For example to calculate a(2136) we first convert to binary:
100001011000
We find our least significant bit
100001011000
^
Take the bit to its ... |
package donothing
// An OutputDef specifies a value that a step outputs for later consumption by another step.
type OutputDef struct {
// The type for values of the output. Either "string" or "int"
ValueType string
// The output's name, which another step can refer to in an InputDef if it wants to use this
// out... |
package leetcode
/*Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops end... |
package waveform
import (
"encoding/binary"
"errors"
"math"
)
// Parser type
type Parser func([]byte) float64
// DecodeWav decode wav file information from bytes
func DecodeWav(bytes []byte) *Wav {
waveFormat := WaveFormat(binary.LittleEndian.Uint16(bytes[20:22]))
numChannels := binary.LittleEndian.Uint16(byte... |
package test
import (
"fmt"
"sort"
"testing"
)
func TestSimple(t *testing.T) {
arr := []int{7, 16, 3, 11, 19, 12, 99, 3, 4, 1}
slice := sort.IntSlice(arr)
sort.Sort(sort.Reverse(slice))
fmt.Println(slice)
}
func TestA(t *testing.T) {
i := rangeBitwiseAnd(1789971928, 1789979928)
fmt.Println(i)
fmt.Prin... |
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/getsalty/Webservice_POC/go/gorilla/src/continent"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/continent", func(w http.ResponseWriter, r *http.Request) {
var continentList []continent.Continent
co... |
package sese
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document00500101 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:sese.005.001.01 Document"`
Message *TransferInInstruction `xml:"sese.005.001.01"`
}
func (d *Document00500101) AddMess... |
package core
import (
"net"
"github.com/grandcat/zeroconf"
)
type MDNSController interface {
advertise(serviceName string, port int, iface []net.Interface)
}
type ConcreteMDNSController struct {
}
func NewConcreteMDNSController() *ConcreteMDNSController {
return &ConcreteMDNSController{}
}
func (c ConcreteMDN... |
package middleware
import (
"encoding/json"
"github.com/gorilla/context"
"gopkg.in/mgo.v2"
"log"
"net/http"
"reflect"
"strings"
"time"
)
// Errors
type Errors struct {
Errors []*Error `json:"errors"`
}
type Error struct {
Id string `json:"id"`
Status int `json:"status"`
Title string `json:"title... |
package quadrequation
import (
"fmt"
"math"
)
type myError struct {
Some string
}
func (e *myError) Error() string {
return fmt.Sprintf("%v", e.Some)
}
func wrong(s string) error {
return &myError{
s,
}
}
func quadrEquation(a, b, c float64) (float64, float64, error) {
var x1, x2 float64
if a == 0 && b =... |
package hat
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httputil"
"testing"
)
// ResponseAssertion requires a quality of the response.
type ResponseAssertion func(t testing.TB, r Response)
// CombineResponseAssertions returns a new ResponseAssertion which internally
// calls each member o... |
package main
import "fmt"
func anotherFunction(f func(string) string) {
result := f("Animal")
fmt.Println(result)
}
func main() {
myFunc := func(s string) string {
return "Hello, " + s
}
anotherFunction(myFunc)
}
|
package main
import (
"fmt"
"strconv"
"strings"
)
var input = []int{0, 5, 10, 0, 11, 14, 13, 4, 11, 8, 8, 7, 1, 4, 12, 11}
func main() {
part1(duplicate(input))
}
func part1(banks []int) {
m := map[string]int{}
count := 0
for !seen(m, banks) {
m[stringify(banks, 0)] = count
redestribute(banks, maxIdx(ban... |
package main
import (
"fmt"
)
func main() {
//赋给一个变量
f := func(x, y int) int {
return x + y
}
result := f(123, 456)
fmt.Println(result)
//定义时直接调用
result = func(x, y int) int {
return x + y
}(789, 91011)
fmt.Println(result)
}
|
package main
/*
引用类型: map / slice / chan
值类型:普通的 int , float , string, byte, rune
TODO: 编写输出参数和原始变量的 address 和 value 的函数
1. 引用类型的value 作为参数被传递的时候,copy 的是指针, 因此依然可以修改原变量的值。 这就是为何 chan 经常作为参数传递,函数中 send, 依然可以在函数外接收到。
TODO: 特别的, go routine 在启动前就会 copy 好相应的参数。 如果没有使用参数传入, 内部引用的 value 可能的取值不确定,因为 go 启动的时间不被保证。
2. 编写 go r... |
package cloudflare
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
// AddressMap contains information about an address map.
type AddressMap struct {
ID string `json:"id"`
Description *string `json:"description,omitempty"`
DefaultSNI *string ... |
package main
import "testing"
func TestAddAge(t *testing.T) {
testFriend := friend{
age: 13,
}
testIncrement := 2
result := addAge(testFriend, testIncrement)
expected := 15
if result != expected {
t.Errorf("Failed Add Age. Expected: %d, Received: %d", expected, result)
}
}
func TestCelebrateBirthday(t *te... |
package key
import (
"encoding/json"
g8sv1alpha1 "github.com/giantswarm/apiextensions/pkg/apis/cluster/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
cmav1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)
func clusterProviderSpec(cluster cmav1alpha1.Cluster) g8sv1alpha1.AWSClusterSpec {
return mustG8sCl... |
package expr
import (
"calc/scanner"
"strconv"
)
type Expr interface {
Accept(v Visitor) interface{}
}
type Visitor interface {
VisitBinaryExpr(expr *Binary) interface{}
VisitGroupingExpr(expr *Grouping) interface{}
VisitLiteralExpr(expr *Literal) interface{}
VisitUnaryExpr(expr *Unary) interface{}
}
type Bi... |
package consumer
import (
"sync"
"sync/atomic"
"log"
"errors"
)
type memoryConsumer struct{
sync.RWMutex
name string
context Context
fork int
incomeChan chan interface{}
memoryChan chan interface{}
running int32
stopChan chan int
requestCount uint64
finishedCount uint64
queue *memQueue
waitGr... |
package lang
import (
"fmt"
"testing"
)
func TestBook(t *testing.T) {
var b = Book{name: "book1"}
var s string = tuple(b.author == "", "nil", "not nil").(string)
fmt.Println("#", b.author, "#", s)
fmt.Println(b)
}
|
package betypes
import (
"fmt"
)
var (
BotToken = "1436657093:AAEp-Vsd91oOWWjfDOhcfn9bNc5wmVzj0yw"
BotExternalAddress = "35.220.142.212"
BotExternalPort = "443"
BotInternalAddress = "0.0.0.0"
BotInternalPort = "5000"
TelegramUrl = "https://api.telegram.org/bot"
MySqlAddress = "local... |
package main
import (
"fmt"
"net/http"
"pastebin/config"
"pastebin/handler"
"time"
)
func main() {
config.ParseYaml()
handler.ParsePrefix()
server := http.Server{
Addr: config.Data.Server.Addr,
Handler: &handler.MyHandler{},
ReadTimeout: 20 * time.Second,
}
fmt.Println("... |
package model
import (
"errors"
"fmt"
"strings"
"time"
"tpay_backend/utils"
"gorm.io/gorm"
)
const (
MerchantStatusEnable = 1 // 启用
MerchantStatusDisable = 2 // 禁用
// 是否是平台商户
IsBelongPlatformTrue = 1 // 是
IsBelongPlatformFalse = 2 // 否
)
const MerchantTableName = "merchant"
type Merchant struct {
Id... |
// Copyright © 2019 IBM Corporation and others.
//
// 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 la... |
package hcsshim
import (
"fmt"
"syscall"
"unsafe"
"github.com/Sirupsen/logrus"
)
// TerminateComputeSystem force terminates a container.
func TerminateComputeSystem(id string, timeout uint32, context string) (uint32, error) {
return shutdownTerminate(false, id, timeout, context)
}
// ShutdownComputeSystem shut... |
package push
import (
"Open_IM/internal/push/jpush/common"
"Open_IM/internal/push/jpush/requestBody"
"Open_IM/pkg/common/config"
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
type JPushResp struct {
}
func JGAccountListPush(accounts []string, content, detailContent, platform string) ([]byte, error) {
var... |
package log
import (
"context"
"net/http"
"time"
)
// StatusResponseWriter implements the http.ResponseWriter interface, by wrapping another
// http.ResponseWriter. It has the ability to record the HTTP response code for logging
// purposes.
type StatusResponseWriter struct {
status int
http.ResponseWriter
}
//... |
package calendarGames
import "fmt"
type ResultGames struct {
games []*game
}
type game struct {
HomeTeam string
VisitTeam string
Result string
Journey int16
}
type CalendarGame interface {
add()
listGames()
}
func (this *ResultGames) add(gameResult *game) {
this.games = append(this.games, gameResult)... |
package main
import "fmt"
func main() {
fmt.Println("Number of Islands")
doTest([][]byte{{'1', '1', '0', '0', '0'}, {'1', '1', '0', '0', '0'}, {'0', '0', '1', '0', '0'}, {'0', '0', '0', '1', '1'}})
doTest([][]byte{{'1', '1', '1', '1', '0'}, {'1', '1', '0', '1', '0'}, {'1', '1', '0', '0', '0'}, {'0', '0', '0', '0',... |
package dto
type UserDto struct {
Username string `json:"username"`
UserId string `json:"user_id"`
Ok bool `json:"ok"`
Role int `json:"role"`
Token string `json:"token"`
}
|
package keeper
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/octalmage/gitgood/x/gitgood/types"
"github.com/stretchr/testify/assert"
)
func createNAchievement(keeper *Keeper, ctx sdk.Context, n int) []types.Achievement {
items := make([]types.Achievement, n)
for i := range items {
i... |
// Package event provides the blockchain data in a structured way.
//
// All asset amounts are fixed to 8 decimals. The resolution is made
// explicit with an E8 in the respective names.
//
// Numeric values are 64 bits wide, instead of the conventional 256
// bits used by most blockchains.
//
// 9 223 372 036 854 775 ... |
package search
import (
"github.com/empirefox/esecend/config"
"github.com/empirefox/esecend/db-service"
"github.com/empirefox/reform"
)
type Resource struct {
Conf *config.Config
Dbs *dbsrv.DbService
View reform.View
// used by Context
scopeMap map[string]*SearchScope
// output to client
scopes []*Search... |
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/Cloud-Foundations/Dominator/lib/constants"
"github.com/Cloud-Foundations/Dominator/lib/flags/commands"
"github.com/Cloud-Foundations/Dominator/lib/flags/loadflags"
"github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger"
"github.com/Cloud-Foundatio... |
package main
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"time"
"strings"
rate "golang.org/x/time/rate"
smartling "github.com/Smartling/api-sdk-go"
"github.com/gobwas/glob"
"github.com/reconquest/hierr-go"
)
func SearchLocale(list []smartling.Locale, locale string) (*smartling.Locale) {
for _, _... |
package main
//只需关注偶数位置上放的全是偶数即可
func sortArrayByParityII(A []int) []int {
j := 1 //i指向偶数位置,j指向奇数位置
for i := 0; i < len(A); i = i + 2 {
if A[i]&1 == 1 { //如果偶数位置上的数是奇数,就一直往下找j的位置,直到找到一个偶数
for A[j]&1 == 1 {
j += 2
}
//找到一个偶数,交换
A[i], A[j] = A[j], A[i]
}
}
return A
}
|
package rand
import (
"encoding/hex"
"fmt"
sdk "github.com/irisnet/irishub/types"
abci "github.com/tendermint/tendermint/abci/types"
)
// BeginBlocker handles block beginning logic for rand
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) (tags sdk.Tags) {
ctx = ctx.WithLogger(ctx.Logger... |
package suites
import (
"testing"
"github.com/go-rod/rod"
"github.com/stretchr/testify/require"
)
func (rs *RodSession) doInitiatePasswordReset(t *testing.T, page *rod.Page, username string) {
err := rs.WaitElementLocatedByID(t, page, "reset-password-button").Click("left", 1)
require.NoError(t, err)
// Fill in... |
package main
import "fmt"
//solution H
func main() {
var sum int // initial sum
var count int
var nums [20]int //[0,0,0,0,0,....]
fmt.Scan(&count)
for i := 0; i < count; i++ {
var value int
fmt.Scan(&value)
nums[i] = value
}
var start, stop int
fmt.Scan(&start)
fmt.Scan(&stop)
for i := start - 1; i... |
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"sync"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
const (
countPerPage = 50... |
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package handlers
import (
"encoding/json"
"io/ioutil"
"net/http"
"time"
"github.com/openfaas/faas/gateway/metrics"
"github.com/openfaas/faas/gateway/reque... |
package broker
import (
"rocketmqtt/logger"
"rocketmqtt/plugins/bridge"
"go.uber.org/zap"
)
var (
log = logger.Instance
)
func (b *Broker) Publish(e *bridge.Elements) {
if bridge.Delivers.ExistTargets() {
err := b.bridgeMQ.Publish(e)
if err != nil {
log.Error("send message to mq error.", zap.Error(err))
... |
// go test -run none -bench . -benchtime 3s -benchmem
// go test -run none -bench BenchmarkSprint/none -benchtime 3s -benchmem
// go test -run none -bench BenchmarkSprint/format -benchtime 3s -benchmem
// basic sub-benchmark test.
package sub_test
import (
"fmt"
"testing"
)
var gs string
// BenchmarkSprint tests ... |
package protol
import (
"bytes"
"errors"
"io"
)
const maxReadLength = 60
// Protocol Reader
type Reader struct {
rd io.Reader
Incoming *bytes.Buffer
endCharacter string
}
// Read a message from io.reader
func (reader *Reader) Read() ([]*Protocol, error) {
var messages = make([]*Protocol, 0, 5)
for {
chunk... |
package workflowtemplate
import (
"context"
"fmt"
"sort"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
workflowtemplatepkg "github.com/argoproj/argo/pkg/apiclient/workflowtemplate"
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/server/auth"
"github.com/argoproj/argo/util/instance... |
package bean
import (
"github.com/HNB-ECO/HNB-Blockchain/HNB/p2pNetwork/common"
)
type TxMsg struct {
Msg []byte
}
//Serialize message payload
func (this TxMsg) Serialization() ([]byte, error) {
return this.Msg, nil
}
func (this *TxMsg) CmdType() string {
return common.TX_TYPE
}
//Deserialize message payload
f... |
package messagepack
import (
"github.com/pkg/errors"
messagePackEncoder "github.com/vmihailenco/msgpack/v5"
"persons.com/api/domain/person"
)
type Person struct{}
func (p *Person) Decode(input []byte) (*person.Person, error) {
person := &person.Person{}
if err := messagePackEncoder.Unmarshal(input, person); er... |
package hello
import "fmt"
func Say() string {
return "Hello!"
}
func SayTo(name string) string {
return fmt.Sprintf("Hello, %s!", name)
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.