text stringlengths 11 4.05M |
|---|
package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wish/ctl/pkg/client"
"os"
)
func deleteCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "delete",
Short: "Update extensions",
RunE: func(cmd *cobra.Command, args []string) error {
return os.Remove(v... |
package ebakusdb
import (
"encoding/hex"
"fmt"
"math/big"
"reflect"
"strconv"
"github.com/ebakus/go-ebakus/common"
)
// hasHexPrefix validates str begins with '0x' or '0X'.
func hasHexPrefix(str string) bool {
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
}
func byteArrayToReflect... |
package main
import (
"fmt"
"github.com/sanguohot/medichain/chain"
"github.com/sanguohot/medichain/etc"
"log"
"time"
"math/big"
)
func main() {
name := etc.ContractController
err, address := chain.GetAddressFromCns(name)
if err != nil {
log.Fatal(err)
}
fmt.Println("ContractController address ===>", addr... |
package ymongo
import (
"context"
"fmt"
"log"
"testing"
"time"
"go.mongodb.org/mongo-driver/bson"
)
func Test_mongo_insert(t *testing.T) {
var ctx = context.Background()
var doc = bson.M{"a": 100, "b": 30}
client, err := NewMongoClient()
defer client.Disconnect(ctx)
if err != nil {
fmt.Println("------a... |
package array_test
import "testing"
func TestArrayInit(t *testing.T) {
var arr [3]int
arr1 := [4]int{1, 2, 3, 4}
arr2 := [...]int{1, 3, 4, 5}
t.Log(arr[0], arr[1], arr[2]) // 0 0 0
t.Log(arr1[1]) // 2
t.Log(arr2) // [1 3 4 5]
}
func TestArrayTravel(t *testing.T) {
arr := [...]... |
package server
import (
"TruckMonitor-Backend/context"
"TruckMonitor-Backend/controller"
)
type Instance struct {
Configuration context.Configuration
}
func (instance Instance) Start() error {
appContext := context.NewApplicationContext(instance.Configuration)
defer appContext.DbContext().Close()
return contr... |
package client
import (
"encoding/json"
"log"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/taglme/nfc-goclient/pkg/models"
)
func TestBuildJobsQueryParams(t *testing.T) {
l := 25
q := buildRunsQueryParams(RunFilter{
Limit: &l,
})
assert.Equal(t, "?li... |
package ZFic
import (
"fmt"
)
//noinspection GoUnusedGlobalVariable
var Serv *ServerConfig
var ZFServ *HttpServer
var DB = &[]*User{}
var Sesses *map[string]*Session
//noinspection GoUnusedExportedFunction
func Load() (*HttpServer, error) {
Archive, err := GetArchive()
LoadDataBase()
LoadSessions... |
package dht
import (
"context"
"sync"
u "gx/ipfs/QmNohiVssaPw3KVLZik59DBVGTSm2dGvYT9eoXt5DQ36Yz/go-ipfs-util"
peer "gx/ipfs/QmPJxxDsX2UbchSHobbYuvz7qnyJTFKvaKMzE2rZWJ4x5B/go-libp2p-peer"
pset "gx/ipfs/QmPJxxDsX2UbchSHobbYuvz7qnyJTFKvaKMzE2rZWJ4x5B/go-libp2p-peer/peerset"
pstore "gx/ipfs/QmQFFp4ntkd4C14sP3FaH9WJ... |
/*
Copyright 2020 The Qmgo 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, sof... |
/*
Given a positive number n, rotate its base-10 digits m positions rightward. That is, output the result of m steps of moving the last digit to the start. The rotation count m will be a non-negative integer.
You should remove leading zeroes in the final result, but not in any of the intermediate steps. For example, ... |
package runner
// This file contains functions and data used to deal with local disk space allocation
import (
"encoding/json"
"fmt"
"sync"
"syscall"
"github.com/dustin/go-humanize"
"github.com/go-stack/stack"
"github.com/karlmutch/errors"
)
type diskTracker struct {
Device string // The local storage devi... |
package server
import (
"fmt"
"github.com/go-chi/render"
log "github.com/sirupsen/logrus"
"net/http"
)
func NewApiRenderer() func(w http.ResponseWriter, r *http.Request, v interface{}) {
return func(w http.ResponseWriter, r *http.Request, v interface{}) {
if err, ok := v.(error); ok {
if _, ok := r.Context(... |
package main
import (
"./controllers"
"./middleware"
"github.com/gin-gonic/gin"
)
func main() {
route := gin.Default()
route.Use(middleware.ConnectDB)
route.GET("/", func(c *gin.Context) {
c.String(200, "Welcome golang")
})
route.POST("/task/manager", controllers.CreateTask)
route.DELETE("/task/manager/... |
package grpcauth
import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/base64"
"encoding/binary"
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"math/big"
"net"
"strings"
"time"
"github.com/cloudflare/cfssl/log"
pb "github.com/immesys/wave/eapi/pb"
"g... |
package file
import (
"encoding/csv"
"fmt"
"net/http"
)
func Read(w http.ResponseWriter, r *http.Request) (records [][]string) {
file, _, err := r.FormFile("file")
if err != nil {
w.Write([]byte(fmt.Sprintf("error %s", err.Error())))
return
}
defer file.Close()
records, err = csv.NewReader(file).ReadAll()... |
package main
import "fmt"
// 同一个结构体实现多个接口
// 接口嵌套
type animal interface {
mover
eater
}
type mover interface {
move()
}
type eater interface {
eat(string)
}
type cat struct {
name string
feet int8
}
// cat同时实现了move()接口和eat()接口
func (c *cat) move() {
fmt.Println("走猫步~")
}
func (c *cat) eat(food string) {
fmt... |
package server_test
import (
"chlorine/server"
"net/http"
"net/http/httptest"
"testing"
)
func TestMyPlaylistsHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/me/playlists", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := server.MyPlaylistsHandler{}
handler.ServeHT... |
package cli
import (
"fmt"
"os"
"github.com/ikaven1024/bolt-cli/cli/command"
"github.com/ikaven1024/bolt-cli/cli/framework"
"github.com/ikaven1024/bolt-cli/db"
)
const info = `Welcome to the boltDB monitor.
Type 'help;' or 'h' for help.
Type 'ctrl+C' to clear the current input statement.
Type 'ctrl+C' to exit ... |
package proxy
import (
"github.com/colefan/gsgo/gameprotocol/protocol_proxy"
"github.com/colefan/gsgo/netio"
"github.com/colefan/gsgo/netio/packet"
)
//节点服务
//管理与各服务器之间的物理连接;
type NodeService struct {
*netio.Server
netio.DefaultPackDispatcher
}
func NewNodeService() *NodeService {
s := &NodeService{}
s.Server... |
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// 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/LIC... |
package response
import (
"encoding/xml"
)
type Response struct {
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
XMLName xml.Name `xml:"xml"`
}
func NewResponse(msgType string) Response {
r... |
package experiment
import (
"context"
"errors"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestExperimentRun(t *testing.T) {
t.Run("success experiment", func(t *testing.T) {
testName := "test-success"
wg := sync.WaitGroup{}
wg.Add(1)
ref := func(ctx context.Context) (interface{... |
package service
import "context"
// ReadOnlyDB used to get database object from any database implementation.
// For consistency reason both TransactionDB and ReadOnlyDB will seek database object under the context params
type ReadOnlyDB interface {
GetDatabase(ctx context.Context) (context.Context, error)
}
// ReadO... |
package main
//go:generate protoc --go-grpc_out=require_unimplemented_servers=false:./grpcapi --go_out=./grpcapi subscribe.proto
import (
"context"
"demo/grpcapi"
"flag"
"log"
"net/http"
"time"
"github.com/gorilla/websocket"
"google.golang.org/grpc"
)
var (
ip = flag.String("ip", "backend", "Backend ... |
package main
import (
corev1 "k8s.io/api/core/v1"
"log"
)
type patches []patchOperation
func (p patches) patchReport() {
log.Printf("--------------APPLYING PATCHES ARE----------------------")
for _, patch := range p {
log.Printf("Operation: %s \n", patch.Op)
log.Printf("Path: %s \n", patch.Path)
log.Printf... |
package postgresql
import(
"testing"
"context"
"github.com/Mindslave/skade/backend/internal/entities"
"github.com/stretchr/testify/require"
)
func TestStoreFile(t *testing.T) {
arg := entities.DbStoreFileParams {
Filename: "testfile",
Filesize: 100,
FileExtension: "exe",
}
err := testrepo.StoreFile(c... |
package rest
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"github.com/brigadecore/brigade/v2/apiserver/internal/api"
"github.com/brigadecore/brigade/v2/apiserver/internal/lib/restmachinery"
"github.com/brigadecore/brigade/v2/apiserver/internal/meta"
"github.com/gorilla/mux"
"github.com/pkg/erro... |
package dao
import (
"bytes"
"fmt"
"ssq-spider/logger"
"ssq-spider/model"
"strings"
)
const (
sysConfigTable = "sys_config_t"
ssqNumberTable = "ssq_number_t"
)
func GetOneSysConfig(typeId string, name string) (string, error) {
db, err := NewMysqlDBClient()
if err != nil {
logger.Logger.Error("NewMysqlDBCl... |
package coordinator
import (
"errors"
"fmt"
. "github.com/fmstephe/matching_engine/msg"
"runtime"
"testing"
)
type chanWriter struct {
out chan *RMessage
}
func newChanWriter(out chan *RMessage) *chanWriter {
return &chanWriter{out: out}
}
func (c chanWriter) Write(b []byte) (int, error) {
r := &RMessage{}
... |
package tdb
import (
"database/sql"
"fmt"
"log"
"time"
)
type dailyreport base
var insertRecodeSQL *sql.Stmt
var err error
func NewDailyReportDB() *dailyreport {
table := "dailyreport"
if insertRecodeSQL, err = conn.Prepare(fmt.Sprintf("Insert into %s(no, filter, timestamp) Values(?,?,?)", table)); err != nil... |
/*
LRUCache is a simple LRU cache. It is based on the LRU implementation in groupcache:
https://github.com/golang/groupcache/tree/master/lru
*/
package sqlmonitor
import "container/list"
import (
"sync"
)
// LRUCache is an LRU cache. It is not safe for concurrent access.
type LRUCache struct {
// MaxEntries is the... |
package core
import (
"math"
"time"
)
type (
score struct {
dones []doneWord
}
doneWord struct {
word string
time time.Duration
}
)
func (s *score) addDoneWord(d doneWord) {
s.dones = append(s.dones, d)
}
func (s *score) averageTime() float64 {
var sumMin float64
for _, done := range s.dones {
sumMi... |
package main
import (
"context"
"log"
"os"
"github.com/rodrigo-brito/ninjabot/example"
"github.com/rodrigo-brito/ninjabot"
"github.com/rodrigo-brito/ninjabot/pkg/exchange"
"github.com/rodrigo-brito/ninjabot/pkg/model"
"github.com/rodrigo-brito/ninjabot/pkg/notification"
)
func main() {
var (
ctx ... |
package main
import "fmt"
func calc(index string, a, b int) int {
ret:=a+b
fmt.Println(index,a,b,ret)
return ret
}
//10 1 2 3
//20 0 2 2
//2 0 2 2
//1 1 3 4 |
package aws
import (
"context"
"os"
"time"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/awslabs/k8s-cloudwatch-adapter/pkg/apis/metrics/v1alpha1"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go... |
// Copyright 2016 Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... |
package main
import (
"fmt"
)
func trap(height []int) int {
sum := 0
if len(height)==0 {
return 0
}
left :=0
right := len(height)-1
maxLeft := 0
maxRight := 0
for ;left < right; {
if height[left] < height[right] {
if maxLeft < height[left] {
maxLeft = height[left]
} else {
sum = sum + (m... |
package models
type Gateway struct {
ID uint `json:"id" gorm:"primary_key"`
Serial string `json:"serial"`
Name string `json:"name"`
IPv4Address string `json:"ipv4Address"`
}
|
package main
import (
"bufio"
"flag"
"fmt"
"os"
"sort"
"strings"
"time"
)
type action int
const (
beginShift action = iota
fallAsleep
wakeUp
)
func (a *action) String() string {
return [...]string{"begins shift", "falls asleep", "wakes up"}[*a]
}
type entry struct {
guard int
action action
tim... |
package main
import (
"fmt"
"io/ioutil"
"net/http"
"path"
"runtime"
"strings"
)
func main() {
// http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// w.Write([]byte("Hello World"))
// })
mux := http.NewServeMux()
mh := &MyHandler{}
mux.Handle("/", mh)
// mh := &MyHandler{}
//http.Ha... |
package facsqs
import (
"github.com/kataras/golog"
facclients "github.com/wagner-aos/go-fast-aws-connections/fac_clients"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
)
var (
err error
sqsAPI sqsiface.SQSAPI
)
//Start - initialize... |
package main
import (
"fmt"
"strconv"
)
type instructionSet struct {
mask string
instructions []instruction
}
type instruction struct {
address int
value int
}
func (i *instruction) getMaskedValue(mask string) int {
base2 := strconv.FormatInt(int64(i.value), 2)
paddedBase2Value := fmt.Sprintf("%03... |
package main
const esbuildVersion = "0.4.1"
|
/*
* Copyright 2018-2019 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by a... |
// +build linux darwin freebsd
package main
import (
"log"
"os"
"os/signal"
"syscall"
kcp "github.com/xtaci/kcp-go/v5"
)
func init() {
go sigHandler()
}
func sigHandler() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGUSR1)
signal.Ignore(syscall.SIGPIPE)
for {
switch <-ch {
case syscal... |
package chatbots
import (
"encoding/json"
"net/url"
"strconv"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
// BotCommand BotCommand
type BotCommand struct {
Command string `json:"command"`
Description string `json:"description"`
}
func (c ChatBot) setMyCommands(commands []BotCommand) (resp... |
// Copyright 2020, OpenTelemetry 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 ag... |
package nilable
// Int represents an int type that can be assigned nil.
type Int struct {
val int
has bool
}
// NilInt creates a new Int without value.
func NilInt() Int {
return Int{}
}
// NewInt creates a new Int with value 'v'.
func NewInt(v int) Int {
return Int{val: v, has: true}
}
// Has reports whether t... |
package _interface
import (
"context"
"github.com/muhammadisa/vanilla-microservice/model"
)
type Repository interface {
WriteTodo(ctx context.Context, todo model.Todo) error
ReadTodos(ctx context.Context) model.Todos
}
|
package main
import (
"database/sql"
"log"
"github.com/MarcelCode/ROWA/src/api"
"github.com/MarcelCode/ROWA/src/db"
"github.com/MarcelCode/ROWA/src/sensor"
"github.com/MarcelCode/ROWA/src/settings"
"github.com/MarcelCode/ROWA/src/util"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func... |
package dispatchers
import (
"errors"
"github.com/jeremija/gol/types"
)
type newDispatcherFunc func(DispatcherConfig) Dispatcher
var dispatchers = map[string]newDispatcherFunc{}
func RegisterDispatcher(name string, createDispatcher newDispatcherFunc) {
if _, ok := dispatchers[name]; ok {
panic("Dispatcher " + ... |
/*
* @lc app=leetcode.cn id=94 lang=golang
*
* [94] 二叉树的中序遍历
*/
package main
import "fmt"
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
// @lc code=start
func inorderTraversal(root *TreeNode) []int {
if root == nil {
return nil
}
ans := []int{}
ans = append(ans, inorderTraversal(roo... |
package collatzconjecture
import "errors"
func CollatzConjecture(n int) (int, error) {
if n < 1 {
return -1, errors.New("n must be greater than zero")
}
var count int
for {
if n == 1 {
return count, nil
}
if n%2 == 0 {
n = n / 2
} else {
n = 3*n + 1
}
count++
}
}
|
package main
import (
"encoding/json"
"sync"
"os"
"net"
"io/ioutil"
"fmt"
"log"
)
type Config struct {
WebServerAddress string `json:"webServerAddress"`
TcpCtrlAddress string `json:"tcpCtrlAddress"`
TcpLogAddress string `json:"tcpLogAddress"`
TcpNotifyAddress string `json:"tcpNotifyAddress"`
E... |
package main
import "fmt"
func main() {
fmt.Println(fib(1), fib(2), fib(3), fib(4), fib(5), fib(6), fib(7))
}
func fib(n int) int {
//atribuicao de tupla, permite que diversas variaveis recebam valores de uma so vez
x, y := 0, 1
for i := 1; i < n; i++ {
y, x = y+x, y
}
return y
}
|
package graphql_test
import (
"testing"
"github.com/ONSdigital/aws-appsync-generator/pkg/graphql"
"github.com/stretchr/testify/assert"
)
func TestNewFilterFromObject(t *testing.T) {
in := &graphql.Object{
Name: "TestObject",
Fields: []*graphql.Field{
{
Name: "name",
Type: &graphql.FieldType{
... |
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
)
type build struct {
Branch string `json:"branch"`
BuildURL string `json:"build_url"`
Workflows workflow `json:"workflows"`
StartTime string `json:"start_time"`
BuildTimeMill... |
package handler
import (
"context"
client "github.com/lecex/core/client"
pb "github.com/lecex/device-api/proto/device"
)
// Device 设备结构
type Device struct {
ServiceName string
}
// All 权限列表
func (srv *Device) All(ctx context.Context, req *pb.Request, res *pb.Response) (err error) {
return client.Call(ctx, srv... |
package ccutility
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"os"
// xxx
_ "net/http/pprof"
"strings"
"time"
)
// GetAllFileByExt .
func GetAllFileByExt(pathname string, ext string, s []string) ([]string, error) {
rd, err := ioutil.ReadDir(pathname)
if err != nil {
log.Pri... |
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
)
var users []User
var medicalRecords []MedicalRecord
var patientHistory []PatientHistory
func main() {
router := mux.NewRouter()
users = append(users, User{Id: "1", UserName: "ganeshRao", FirstName: "Ganesh", LastName: "Rao", Address: "Mahalaksh... |
// Copyright 2019-2023 The sakuracloud_exporter 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 appl... |
package nebulatest
import (
"encoding/json"
"fmt"
"github.com/vesoft-inc/nebula-go/graph"
)
type JsonDiffer struct {
DifferError
Response *graph.ExecutionResponse
Order bool
}
func (d *JsonDiffer) Diff(result string) {
// result = fmt.Sprintf("%q", result)
var resp executionResponse
if err := json.Unmar... |
package download
import (
"fmt"
"os"
"net/http"
"io/ioutil"
"io"
"bytes"
)
func DownloadImg(id string, url string) () {
go func() {
out, err := os.Create("H:\\wallpager\\" + id + ".jpg")
if err != nil {
fmt.Printf("download err %s \n", err.Error())
}
defer out.Close()
resp, err := http.Get(url)
... |
package cgo
import (
"crypto/rand"
"crypto/subtle"
"encoding/base64"
"errors"
"fmt"
"strings"
"golang.org/x/crypto/argon2"
)
var (
// ErrInvalidHash error
ErrInvalidHash = errors.New("the encoded hash is not in the correct format")
// ErrIncompatibleVersion error
ErrIncompatibleVersion = ... |
package main
import (
"fmt"
"sort"
)
func main() {
fmt.Println(getLeastNumbers([]int{3, 2, 1}, 2))
fmt.Println(getLeastNumbers([]int{0, 1, 2, 1}, 1))
fmt.Println(getLeastNumbers([]int{4, 5, 1, 6, 2, 7, 3, 8}, 4))
}
func getLeastNumbers(arr []int, k int) []int {
sort.Ints(arr)
return arr[:k]
}
func getLeastN... |
// Copyright 2019 Google Inc. 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... |
package client
import (
"encoding/json"
"log"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/taglme/nfc-goclient/pkg/models"
)
func TestHandleHttpResponseCode(t *testing.T) {
err := handleHttpResponseCode(http.StatusOK, []byte("message"))
assert.Nil(t, err)
resp, err := json.Marshal... |
// Copyright 2023 Google 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 required by applica... |
// Copyright 2023 Google 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 required by applica... |
/*****************************************************************
* Copyright©,2020-2022, email: 279197148@qq.com
* Version: 1.0.0
* @Author: yangtxiang
* @Date: 2020-07-21 11:54
* Description:
*****************************************************************/
package xthrift
import (
. "github.com/apache/thrift/li... |
package leetcode
import (
"fmt"
"testing"
)
func TestHammingWeight(t *testing.T) {
fmt.Println(HammingWeight(11))
}
func TestIsPowerOfTwo(t *testing.T) {
t.Log(isPowerOfTwo(6))
}
|
package clls
import (
"context"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"github.com/clls-dev/clls/pkg/examples"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/pkg/errors"
lsp "go.lsp.dev/protocol"
"go.lsp.dev/uri"
"go.uber.org/zap"
)
var (
CommandName = "clls"
)
func readFileToString(u lsp.DocumentU... |
package isaac
import (
"time"
)
const (
actionsBasePath = "/api/v1/logs/scenarios"
)
type ActionsService interface {
Add(NewAction) (Action, error)
Get(ID) (Action, error)
List() ([]Action, error)
Remove(Action) error
Update(Action) (Action, error)
}
type ActionsServiceOp struct {
client *Client
}
type New... |
package core
import "fmt"
//AOI 区域管理模块
type AOIManager struct {
//区域左边界坐标
MinX int
//区域右边界坐标
MaxX int
//X方向格子的数量
CntsX int
// 区域的上边界坐标
MinY int
// 区域的下边界坐标
MaxY int
//Y方向格子的数量
CntsY int
// 当前区域中有哪些格子map: key 格子的ID value 格子的对象
grids map[int] *Grid
}
// 初始化一个AOI区域管理模块
func NewAOIManager(minX, maxX... |
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"sync"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
const (
//DotFile The file in HOME user
DotFile = ".github-command-line"
)
//Config Configuration Appl... |
package imp0rt
import (
"encoding/json"
"io"
"os"
"github.com/Zenika/marcel/api/db"
)
func imp0rt(inputFile string, value interface{}, save func() error) error {
if err := db.Open(); err != nil {
return err
}
defer db.Close()
var r io.ReadCloser
if inputFile == "" {
r = os.Stdin
} else {
var err err... |
package pivot
import (
"io/ioutil"
"path"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"github.com/openshift/origin/pkg/oc/clusterup/componentinstall"
"github.com/openshift/origin/pkg/oc/clusterup/docker... |
package user
import (
"bytes"
"fmt"
"log"
"net/http"
"net/http/httptest"
"syscall"
"github.com/cswank/quimby/internal/auth"
"github.com/cswank/quimby/internal/repository"
"golang.org/x/crypto/ssh/terminal"
)
func Create(r *repository.User, username string) {
fmt.Print("Enter password: ")
pw, err := termin... |
package sendtx
import (
"context"
"crypto/ecdsa"
"fmt"
"log"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)
// send signed tx to given chain
func SendTransaction(eth strin... |
package model
import (
"context"
"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/bson/primitive"
"github.com/mongodb/mongo-go-driver/mongo/options"
log "github.com/sirupsen/logrus"
"testing"
"time"
)
// TestInitClient ...
func TestInitClient(t *testing.T) {
client, _ := InitClien... |
package binance
import (
"context"
"net/http"
"github.com/adshao/go-binance/v2/common"
)
// ListBookTickersService list best price/qty on the order book for a symbol or symbols
type ListBookTickersService struct {
c *Client
symbol *string
}
// Symbol set symbol
func (s *ListBookTickersService) Symbol(symb... |
package main
import (
"net/http/httptest"
"testing"
)
func TestCodeRun(t *testing.T) {
var ts *httptest.Server
ts, args = mockAPI(`{}`)
defer ts.Close()
prepareScript("def test():\n\treturn 'test'")
rc := &RunCode{}
err := rc.Run()
if err != nil {
t.Error(err)
}
}
|
package awsvaultcredsprovider
import (
"context"
"crypto/sha1"
"encoding/json"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/jcmturner/vaultclient"
gootp "gopkg.in/jcmturner/gootp.v1"
"ti... |
package connrt
import (
"math/rand"
"time"
"github.com/golang/mock/gomock"
"github.com/gookit/event"
"github.com/kbence/conndetect/internal/connlib"
"github.com/kbence/conndetect/internal/ext_mock"
"github.com/kbence/conndetect/internal/utils_mock"
. "gopkg.in/check.v1"
)
var _ = Suite(&PortscanDetectorTestS... |
package data
import (
"fxkt.tech/bj21/internal/conf"
"fxkt.tech/bj21/internal/data/logic"
"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
)
var (
ProviderSet = wire.NewSet(NewData, Newbj21Repo)
)
type Data struct {
world *logic.World
}
func NewData(c *conf.Data, logger log.Logger) (*Data, func()... |
package main
import "fmt"
func main() {
var str1 string = "\\\""
fmt.Println(str1)
var numbers2 [5]int
numbers2[0] = 2
numbers2[3] = numbers2[0] - 3
numbers2[1] = numbers2[2] + 5
numbers2[4] = len(numbers2)
sum := 0
for i := 0; i < 5; i++ {
sum += numbers2[i]
}
// “==”用于两个值的相等性判断
fmt.Printf("%v\n",... |
package main
import (
"crypto/rand"
"fmt"
smpp "github.com/mergenchik/smpp34"
gsmutil "github.com/mergenchik/smpp34/gsmutil"
"math"
)
func main() {
// connect and bind
tx, err := smpp.NewTransmitter(
"localhost",
9000,
5,
smpp.Params{
"system_type": "CMT",
"system_id": "hugo",
"password": ... |
package server
import (
"context"
"net/http"
"github.com/chitoku-k/ejaculation-counter/supplier/infrastructure/config"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type engine struct {
ctx context.Context
Environment config.Environment
}
type Engine interface... |
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetInt8Slice(t *testing.T) {
t.Run("GetAbsentInt8SliceWithDefault", func(t *testing.T) {
def := []int8{21, 22}
res := env.GetInt8Slice("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetVa... |
package main
import (
"github.com/julienschmidt/httprouter"
"github.com/vincentserpoul/playwithsql/status/islatest"
)
func globalMux(env *localEnv) *httprouter.Router {
router := httprouter.New()
router.POST("/entityone/status/islatest", islatest.EntityoneCreateHandler(env.DB, env.IslatestLink))
router.GET("/en... |
// 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 main
import "fmt"
func main() {
greeting := []string{
"Good morning!",
"Bonjour!",
"dias!",
"Bongiorno!",
"Ohayo!",
"Selamat pagi!",
"Gutten morgen!",
}
for i, currentEntry := range greeting {
fmt.Println(i, currentEntry)
}
for j := 0; j < len(greeting); j++ {
fmt.Println(greeting[j]... |
package mirror
import (
"context"
"errors"
"time"
"github.com/google/uuid"
)
// Config holds configuration data that are needed to create a mirror (pulling mirror credentials, urls, keys
// and any other details).
type Config struct {
NamespaceID uuid.UUID
RootName string
URL string
GitR... |
package stemcell
type Infrastructure interface {
CreateStemcell(Manifest) (CID, error)
// DeleteStemcell(CID) error
}
type infrastructure struct{}
|
/**
* 功能描述: 对application中的module进行调谐
* @Date: 2019-11-14
* @author: lixiaoming
*/
package controllers
import (
"context"
"fmt"
appv1 "github.com/xm5646/paas-crd-application/api/v1"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pk... |
package httputil
import (
"bytes"
"io"
"net/http"
"os"
"text/template"
"time"
)
type templater struct {
fs http.FileSystem
includes map[string]bool
data interface{}
}
var _ http.FileSystem = (*templater)(nil)
func (t *templater) Open(path string) (http.File, error) {
if !t.includes[path] {
ret... |
package main
import (
"basic-rabbitmq/RabbitMQ"
"fmt"
)
func main() {
rabbitmq := RabbitMQ.NewRabbitMQSimple("goSimple")
rabbitmq.PublishSimple("Hello, RabbitMQ!")
fmt.Println("Send success!")
}
|
package model
import (
"errors"
"fmt"
)
// Move is a struct that represents a chess move
type Move struct {
X, Y int8
}
func (move *Move) String() string {
return fmt.Sprintf("%d,%d", move.X, move.Y)
}
var (
diagonalMoves = []Move{{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}
straightMoves = []Move{{0, 1}, {0, -1}, {1,... |
package dbi
import (
// _ "github.com/go-goracle/goracle"
_ "github.com/go-sql-driver/mysql"
// _ "github.com/lib/pq"
// _ "github.com/mattn/go-sqlite3"
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.