text stringlengths 11 4.05M |
|---|
package main
import (
"./BLC"
)
func main() {
//bc := BLC.CreatBlockChain()
//bc.AddBlock("Block1 : 100PHB")
//bc.AddBlock("Block2 : 200PHB")
//bc.VisitBlockChain()
cli := BLC.CLI{}
cli.Run()
}
|
package db
import (
"fmt"
"github.com/trongtb88/rateservice/api/models"
"gorm.io/driver/mysql"
"log"
_ "gorm.io/driver/mysql"
"gorm.io/gorm"
)
type Conn struct {
DB *gorm.DB
}
func Initialize(Dbdriver, DbUser, DbPassword, DbPort, DbHost, DbName string) *gorm.DB {
var (
db *gorm.DB
err error
)
if ... |
package domain
import (
"time"
"github.com/pkg/errors"
)
// Challenge ...
type Challenge struct {
AccountID ID `json:"account_id" db:"account_id"`
ID ID `json:"id" db:"id"`
ForUserID ID `json:"for_user_id" db:"for_user_id"`
Status Stat... |
package main
import (
"bytes"
"encoding/json"
"flag"
"io/ioutil"
"log"
"net/http"
"github.com/go-chi/chi"
"github.com/rastasi/go-messenger-bot/models"
)
const (
verifyToken = "goforever"
pageAccessToken = "EAACChyvB7ZCMBAPXK1i9VDFJyPdEEArsMuAuGNFsuCvfe9Sp6LCX21Rkmii580x25GKUVrEYQkx7BDPdOgnibTt9I9jIx4uI... |
package main
type RequestType int
var (
MSG_REGISTER = RequestType(0)
MSG_SEND = RequestType(1)
MSG_GET = RequestType(2)
)
type Request struct {
Type RequestType `json:"type"`
Name *string `json:"name"`
Text *string `json:"text"`
}
func NewRegisterRequest(name string) Request {
return Request{
Type: M... |
package handlers
import (
"fmt"
"net/http"
)
func RootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
errorHandler(w, r, http.StatusNotFound)
return
}
fmt.Fprintln(w, "Welcome to server")
}
func errorHandler(w http.ResponseWriter, r *http.Request, status int) {
w.WriteHeader(status... |
package main
import (
"log"
"net/http"
"strconv"
"time"
"fcm-app-server/models"
"fcm-app-server/redis"
sq "github.com/Masterminds/squirrel"
)
func v1SmsHandler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
log.Println("Error parsing form data", err)
return
}
log.Print... |
package ravendb
import (
"net/http"
)
var (
_ IMaintenanceOperation = &PutConnectionStringOperation{}
)
type PutConnectionStringOperation struct {
connectionString interface{}
Command *PutConnectionStringCommand
}
func NewPutConnectionStringOperation(connectionString interface{}) *PutConnectionStringOperation ... |
package main
import (
"github.com/micro/go-log"
"github.com/micro/go-micro"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/server"
httpClient "github.com/hb-go/micro-plugins/client/istio_http"
httpServer "github.com/hb-go/micro-plugins/server/istio_http"
"github.com/hb-go/micro/istio/http/srv/ha... |
package Intersection_of_Two_Arrays
import "sort"
func intersection(nums1 []int, nums2 []int) []int {
var result []int
var isSame = make(map[int]bool)
for _, v := range nums1 {
isSame[v] = true
}
for k, v := range nums2 {
if isSame[v] {
result = append(result, nums2[k])
isSame[v] = false
}
}
retu... |
// KAMİL KAPLAN
package test
import (
"encoding/json"
"github.com/icobani/goweather"
"io/ioutil"
"log"
"testing"
)
func TestForeCast(t *testing.T) {
apiKey := "Dl8ehKD1lCgL0GT6WCkGfRh9NtSn5GMO"
c := goweather.NewClient(nil, apiKey)
var code string = "325236"
// Daha önce aranan code var ise onu code'a gö... |
/*
Copyright 2018 The Kubernetes 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, ... |
package utils
//#region Header
import (
mod "../models"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"net/http"
"os"
"strconv"
"time"
)
const (
GITHUB_ENDPOINT string = "https://api.github.com"
USER_AGENT string = "Dmitriy-Vas/go-discord-bot"
MEDIA_TYPE string = "application/vnd.github.v3+json"
SUC... |
package gin
import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/surmus/injection"
"github.com/surmus/injection/test"
"net/http"
"testing"
)
var middlewareFnExecuted bool
const ctrlPostEndpoint = "/test-path-post"
const ctrlGetEndpoint = "/test-path-get"
type PointerController ... |
package main
import (
"context"
"net/http"
"time"
log "github.com/Sirupsen/logrus"
jwt "github.com/dgrijalva/jwt-go"
"github.com/golang/protobuf/ptypes"
"github.com/yogyrahmawan/client_grpc_logger_service/pb"
glb "github.com/yogyrahmawan/grpcloadbalancing"
"google.golang.org/grpc"
"google.golang.org/grpc/c... |
package flagtag
import (
"flag"
"os"
"strconv"
"strings"
"testing"
"time"
)
func TestConfigureNil(t *testing.T) {
if Configure(nil) == nil {
t.Fatal("Expected an error, since nil cannot be parsed.")
}
}
func TestConfigureUntaggedStruct(t *testing.T) {
var s = struct {
A int
B uint
C string
}{}
if ... |
// +build ignore
package main
import (
"github.com/shurcooL/httpfs/filter"
"github.com/shurcooL/httpfs/union"
"github.com/shurcooL/vfsgen"
"net/http"
)
func main() {
fs := union.New(map[string]http.FileSystem{
"/static": filter.Skip(http.Dir("static"), filter.FilesWithExtensions(".go")),
"/templates": ht... |
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// TODO maybe there is better place for this
package fpath
import "context"
// The key type is unexported to prevent collisions with context keys defined in
// other packages.
type key int
// temp is the context key for temp struct.
con... |
package leetcode
func isPowerOfTwo2(n int) bool {
if n == 0 {
return false
}
i := 1
for i < n {
i <<= 1
}
return n == i
}
|
// Copyright (C) 2017 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 t... |
package steps
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
survey "github.com/AlecAivazis/survey/v2"
"github.com/go-ini/ini"
"github.com/pganalyze/collector/setup/query"
"github.com/pganalyze/collector/setup/state"
s "github.com/pganalyze/collector/setup/state"
)
var Specify... |
// Copyright 2020 The SwiftShader Authors. 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 b... |
package hash
import "reflect"
type Entry struct {
Name string
Numbers []int
}
func hasDuplicates(es []*Entry) bool {
m := make(map[uint64][]*Entry)
for i, e := range es {
h := deriveHash(e)
for _, f := range m[h] {
if reflect.DeepEqual(e, f) {
return true
}
}
if _, ok := m[h]; !ok {
m[h] ... |
package rand
const (
mtSize = 624
mtPeriod = 397
mtDiff = mtSize - mtPeriod
)
type MT struct {
Data []uint32
Index uint32
}
var MATRIX [2]uint32
var y, i uint32
// MACROS
func m32(val uint32) uint32 {
return (0x80000000 & val)
}
func l31(val uint32) uint32 {
return (0x7FFFFFFF & val)
}
func isOdd(val... |
// SPDX-License-Identifier: MIT
// Package cmd 提供子命令的相关功能
package cmd
import (
"flag"
"fmt"
"io"
"os"
"github.com/issue9/cmdopt"
"github.com/issue9/term/v3/colors"
"golang.org/x/text/message"
"github.com/caixw/apidoc/v7/core"
"github.com/caixw/apidoc/v7/internal/locale"
)
// 命令行输出的表格中,每一列为了对齐填补的空格数量。
cons... |
package elasticsearch
import (
"fmt"
"github.com/olivere/elastic"
)
type ElasticSearch struct {
Name string
Mapping map[string]interface{}
client *elastic.Client
}
type ElasticSearchClientReq struct {
Host string
Port string
SecondaryPort string
IndexName string
Mapping map... |
package datastructandalgorithm
//求解next数组
func next(sub string) []int {
subSlice := []byte(sub)
subLength := len(subSlice)
next := make([]int, subLength)
next[0] = 0
/*
求解相同前缀和后移获取next数组可以同时跑
这里为了直观,分两步(优化见moreEffectiveNext函数)
*/
//1.求解相同前缀、后缀长度数组
for i, j := 0, 1; j < subLength; j++ {
if subSlice[i] ==... |
package tool
import "encoding/json"
func JSONToString(data interface{}) string {
if marshal, err := json.Marshal(data); err == nil {
return string(marshal)
}
return ""
}
|
package gorm2
import (
"context"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/traPtitech/trap-collection-server/src/domain"
"github.com/traPtitech/trap-collection-server/src/domain/values"
"github.com/traPtitech/trap-collection-server/src/repository"
"github.com/traPtitech/trap-collection-server/src/re... |
package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/dopgm/goconvey-settings-file/config"
)
func TestStub(t *testing.T) {
Convey("Test is working.", t, func() {
So(true, ShouldBeTrue)
})
}
func TestConfig(t *testing.T) {
Convey("Config should be accessible", t, func() {... |
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
package aws
import (
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/golang/mock/gomock"
)
func (a *AWSTestSuite) TestDynamoDBEnsureTableDeleted() {
gomock.InOrder(
a.Mocks.API.DynamoDB... |
package main
import (
"github.com/Kalimaha/ginkgo/reporter"
"github.com/aws/aws-lambda-go/events"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestHello(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithCustomReporters(t, "Hello API Suite", []Reporter{reporter.New()})
}
var _ = D... |
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func doubleTrouble(q string) uint {
var r uint = 1
n := len(q) / 2
for i := 0; i < n; i++ {
if ((q[i] == 'A') && (q[i+n] == 'B')) ||
((q[i] == 'B') && (q[i+n] == 'A')) {
r = 0
break
} else if (q[i] == '*') && (q[i+n] == '*') {
r *= 2
}
}
retu... |
package handler
import (
"main/app"
"strconv"
)
const pageSize = 10 // 每页显示的数据量
func offset(page int) int {
if page == 0 {
return 0
}
return (page - 1) * pageSize
}
// 成功时返回的数据,格式化失败时返回空字符串
func succ(data interface{}) app.SuccRes {
res := app.SuccRes{
Code: 0,
Msg: "success",
Data: data,
}
return r... |
/*
Copyright 2014 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 law or agreed to in ... |
package main
// #include <stdlib.h>
// #include <classification.h>
import "C"
import (
"container/list"
"sync"
"time"
)
const (
MEM_LEAK_CORRECTION = 150 * 1024 * 1024
)
type GPUMem struct {
InitLock sync.Mutex
LRU *list.List
LRULock sync.Mutex
}
type LoadedModelsMap struct {
sync.RWMutex
Models map[... |
package blockchain
import (
"bytes"
"encoding/gob"
"time"
)
/**
* 区块结构体的定义
*/
type Block struct {
Height int64 //区块高度
TimeStamp int64 //时间戳
Hash []byte //区块的hash
Data []byte //数据
PrevHash []byte //上一个区块的hash
Version string //版本号
Nonce int64 //随机数,用于POW工作量证明算法计算
}
/**
*构建一个区块实例,并返回该区块
*/
func NewBlock(he... |
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, ... |
package nano_test
import (
"testing"
"github.com/shibukawa/nanovgo"
"github.com/waybeams/assert"
"github.com/waybeams/waybeams/pkg/env/nano"
)
func TestNanoSurface(t *testing.T) {
t.Run("Instantiable", func(t *testing.T) {
instance := nano.NewSurface()
assert.NotNil(instance)
})
t.Run("Debug Flag", func... |
package mongo
import (
"fmt"
"gopkg.in/mgo.v2"
)
type Config struct {
Host string
Port string
Username string
Password string
Db string
}
func New(c *Config) *Mongo {
url := fmt.Sprintf("mongodb://%v:%v@%v:%v/%v", c.Username, c.Password, c.Host, c.Port, c.Db)
fmt.Println("mongo:", url)
sessi... |
package main
import (
"fmt"
"strings"
"testing"
)
func TestPrimeLess(t *testing.T) {
for k, v := range map[uint]string{
10: "2,3,5,7",
20: "2,3,5,7,11,13,17,19",
100: "2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97",
42: "2,3,5,7,11,13,17,19,23,29,31,37,41"} {
if r := primeLes... |
// 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 wallpaper
import (
"context"
"path/filepath"
"time"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/ash"
"chromiumos/tast/local/chrome/uiauto"
"... |
package http
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"go.elastic.co/apm/module/apmhttp"
"go.elastic.co/apm/module/apmlogrus"
)
func Do(req *http.Request, ctx context.Context, log *logrus.Logger) (string, error) {
// logger
vars := mux.Vars(req)
... |
package definition
import "fmt"
type EngineOneC struct {
IsStarting bool
}
type EngineTwoC struct {
IsStarting bool
}
func (ec *EngineOneC) StartEngineC() {
ec.IsStarting = true
fmt.Println("Engine one been started")
}
func (ec *EngineOneC) StopEngineC() {
ec.IsStarting = false
fmt.Println("Engine one been s... |
package main
import (
"fmt"
"runtime"
)
func main3() {
fmt.Println(runtime.GOOS)
fmt.Println(runtime.NumCPU())
fmt.Println(runtime.NumGoroutine())
} |
/*
Copyright 2014 Jiang Le
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, software
distri... |
package main
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/ledongthuc/pdf"
"github.com/nguyenthenguyen/docx"
)
var keywords []string
func init() {
fmt.Printf("输入关键词,多个关键词以空格分割: ")
inputReader := bufio.NewReader(os.Stdin)
kw, err := inputReader.ReadString('\n')
if err != nil {
... |
package main
import (
"github.com/Altruiste1/go_learning/crawler/Concurrent_crawler/engine"
"github.com/Altruiste1/go_learning/crawler/Concurrent_crawler/scheduler"
"github.com/Altruiste1/go_learning/crawler/Concurrent_crawler/zhenai/parser"
)
func main() {
//engine.Run(engine.Request{
// Url: "https://ww... |
package explainer
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestModel(t *testing.T) {
RegisterFailHandler(Fail)
RunExplainerTests()
RunSpecs(t, "explainer suite")
}
|
package data
import (
"fmt"
config "github.com/spf13/viper"
"github.com/trapped/gomaild2/db"
. "github.com/trapped/gomaild2/smtp/structs"
"strings"
"time"
)
func receivedString(c *Client, e *db.Envelope) string {
secure, authenticated := "", ""
if c.GetBool("secure") {
secure = "S"
}
if c.GetBool("authent... |
package main
import (
"fmt"
"strings"
)
func main() {
var a [2]string
a[0] = "a"
fmt.Println(a)
a[1] = "b"
fmt.Println(a)
// more-types/array.go:11:3: invalid array index 2 (out of bounds for 2-element array)
// a[2] = "c"
//for i := 0; i < 5; i++ {
// a[i] = fmt.Sprintf("no.%d", i)
// //panic: runtime e... |
package game
import (
"encoding/json"
)
type RawMessageIn struct {
Type string
Payload json.RawMessage
}
type MessageIn struct {
Player *Player
Type string
Payload json.RawMessage
}
type MessageOut struct {
Type string
Payload interface{}
}
|
package forms
import (
"encoding/base64"
"errors"
"fmt"
"net/url"
"regexp"
"strings"
"github.com/porter-dev/porter/internal/kubernetes"
"github.com/porter-dev/porter/internal/models"
"github.com/porter-dev/porter/internal/repository"
"k8s.io/client-go/tools/clientcmd/api"
ints "github.com/porter-dev/porte... |
package problem0202
func isHappy(n int) bool {
if n == 0 {
return false
}
if n == 1 {
return true
}
k := 0
m := make(map[int]int)
return recursive(n, k, m)
}
func recursive(n, k int, m map[int]int) bool {
if n == 1 {
return true
}
sum := 0
for n != 0 {
sum += (n % 10) * (n % 10)
n /= 10
}
i... |
package main
import (
"fmt"
)
var i = 5
var str = "ABC"
type person struct {
name string
age int
}
type any interface{}
func main() {
var val any
val = 5
fmt.Println("val value is :", val)
val = str
fmt.Println("val has value is :", val)
pers1 := new(person)
pers1.name = "Bear Chen"
pers1.age = 55
v... |
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package upstart interacts with the Upstart init daemon on behalf of local tests.
package upstart
import (
"context"
"time"
"chromiumos/tast/errors"
"chromiumos/tast/... |
package main
import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/nicolas-nannoni/fingy-gateway/events"
"github.com/parnurzeal/gorequest"
"net/url"
)
type Service struct {
Id string
Host string
Port uint
deviceRegistry map[string]*connection
}
type registry struct {
services map[... |
package watch
import (
"context"
"etcd-config/pkg/config"
"fmt"
clientv3 "go.etcd.io/etcd/client/v3"
"log"
"net/http"
"os"
"strings"
"time"
)
const (
defaultWatchPath = "/configs"
defaultDialTimeout = 5 * time.Second
)
func Execute() error {
pwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
re... |
package rangelist
import (
"fmt"
)
type RangeList struct {
entries []*RangeListEntry
}
type RangeListEntry struct {
Min int
Max int
Data interface{}
}
func (rl *RangeList) PrintEntries() {
for _, entry := range rl.entries {
fmt.Printf("%s\n", entry.String())
}
}
func (entry RangeListEntry) String() stri... |
package profile
import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"golang.org/x/exp/maps"
)
// OnGetConfiguration handles the CS message
func (s *Core) OnGetConfiguration(request *core.GetConfigurationRequest) (confirmation *core.GetConfigurationConfirmation, err error) {
s.log.TRACE.Printf("recv: %s %+v", ... |
package tokencache
import (
"context"
"crypto"
"io"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sassoftware/relic/v7/token"
"golang.org/x/time/rate"
)
var metricRateLimited = promauto.NewCounter(prometheus.CounterOpts{
Name: "... |
package models
import (
"time"
"github.com/kamalraimi/recruiter-api/config"
)
type Application struct {
ID uint `gorm:"primary_key" form:"id" json:"id"`
Civility string `sql:"type:enum('mr','mrs','miss');DEFAULT:'mr'"`
Name string `gorm:"type:varchar(100);index"`
BirthDay ti... |
/***
Copyright 2014 Cisco Systems 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 law or agreed to... |
package controller
import (
"container/list"
"fmt"
"message/src/cn/cncommdata/study/model"
"sync"
"time"
)
func helloWorld() {
a := 1
c := &a
b := "hello world"
fmt.Printf("变量a地址地址为 %s \r\n", &a)
fmt.Printf("变量a值为 %v \r\n", *&a)
fmt.Printf("变量b地址地址为 %s \r\n", &b)
fmt.Printf("变量b值为 %v \r\n", *&b)
fmt.Pr... |
package nifdc
import (
"encoding/gob"
"fmt"
"github.com/json-iterator/go"
"os"
"test.com/a/grequests"
"testing"
)
func TestLogin(t *testing.T) {
}
func TestRe(t *testing.T) {
olds := `
<html>
<head>
<title>普通食品检验填报</title>
<link href="/test_platform/css/bootstrap.min.css?v=1.0.1" rel="styles... |
/*
Copyright 2022 Gravitational, 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 writing, soft... |
package bpi
import "github.com/dasfoo/i2c"
// BrightPI i2c wrapper. Built from code examples at:
// https://www.pi-supply.com/bright-pi-v1-0-code-examples/
// and register specification at:
// http://www.semtech.com/images/datasheet/sc620.pdf (page 14)
//
// Example usage:
// b := bpi.NewBrightPI(bus, bpi.DefaultBP... |
package usecase
import (
"fmt"
"context"
"github.com/pkg/errors"
"github.com/utahta/momoclo-channel/dao"
"github.com/utahta/momoclo-channel/entity"
"github.com/utahta/momoclo-channel/event"
"github.com/utahta/momoclo-channel/event/eventtask"
"github.com/utahta/momoclo-channel/linenotify"
"github.com/utahta/... |
package api
import "log"
import "net/http"
import "github.com/peaberberian/GoBanks/auth"
var apiCalls = map[string]string{
"authentication": "auth",
"transactions": "transactions",
"banks": "banks",
"accounts": "accounts",
"categories": "categories",
"users": "users",
}
// handle... |
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"strings"
_ "github.com/go-sql-driver/mysql"
)
type article struct {
ID int
Title string
Content string
}
var (
articles []article
db *sql.DB
err error
)
func index(w http.ResponseWriter, r *http.R... |
package api
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/mazrean/gold-rush-beta/openapi"
)
var (
exploreCalledNum int64 = 0
exploreMetricsLocker = sync.RWMutex{}
exploreRetryNum = []int{}
exploreRequestTimeLocker = sync.Mutex... |
package main
import (
"encoding/base64"
"fmt"
"net/http"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
requestString := r.URL.EscapedPath()[1:]
requestURL, err := base64.StdEncoding.DecodeString(requestString)
if err == nil {
fmt.Println("Redirected to " + string(requestURL))
http.Redirect(w... |
package model
import "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
type WatchSettings struct {
Ignores []Dockerignore
}
func (ws WatchSettings) Empty() bool {
return len(ws.Ignores) == 0
}
type Dockerignore struct {
// The path to evaluate the dockerignore contents relative to
LocalPath string
// A human-... |
package main
import (
"context"
"fmt"
"github.com/hashicorp/consul/api"
"google.golang.org/grpc"
"net"
"socket/golearn/02-goMicro/pb"
)
type Worker struct {
}
func (worker *Worker) SayHello(ctx context.Context, p *pb.Person) (*pb.Person,error){
p.Age +=10
fmt.Println("age is :",p.Age)
return p,nil
}
func... |
package crud
// TODO: mark ID as comparable
import (
"context"
"github.com/adamluzsi/frameless/ports/iterators"
)
type Creator[Entity any] interface {
// Create is a function that takes a pointer to an entity and stores it in an external resource.
// And external resource could be a backing service like Postgre... |
package typgen_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/typical-go/typical-go/pkg/typgen"
)
func TestFile_SourceCode(t *testing.T) {
testCases := []struct {
TestName string
File *typgen.File
Expected string
}{
{
File: &typgen.File{
Name: "some package",
Im... |
package tests
import (
"fmt"
"testing"
"github.com/Emoto13/photo-viewer-rest/auth-service/src/user"
"github.com/Emoto13/photo-viewer-rest/auth-service/tests/setup"
)
func TestUserRetrieval(t *testing.T) {
db, _ := setup.OpenPostgresDatabaseConnection()
db.Exec(setup.CreateUsersTable)
db.Exec(setup.CreateTestU... |
package main
import (
"errors"
"io/ioutil"
"net/http"
"net/url"
)
func getURLFromStr(urlStr string, check bool) (*url.URL, error) {
url, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
if check {
// A valid URL is defined by one that has a host,
// not empty path (at least '/') and 'https' o... |
package apigw
import (
"context"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/config/cmd"
"log"
"net/http"
"xj_web_server/module"
publicProto "xj_web_server/module/public/proto"
"xj_web_server/module/selector"
)
func init() {
cmd.Init()
client.DefaultClient = cli... |
package collector
import (
"strings"
"bufio"
"bytes"
"strconv"
"os/exec"
"../storage"
"regexp"
"github.com/prometheus/common/log"
"github.com/prometheus/client_golang/prometheus"
)
/*
* Prometheus specifics
*/
var sizeOfBlockDevice = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "block_device_... |
package proto
//Builder protobuf消息构建器
type Builder struct {
}
//InvalidTarget 构建无效转发目标消息
func (b Builder) InvalidTarget() interface{} {
return InvalidTargetMsg{}
}
|
package file_process
import (
"io"
"os"
)
func CopyFile(toFile, fromFile string) (n int64, err error) {
fromfile, err := os.Open(fromFile)
if err != nil {
return
}
defer fromfile.Close()
tofile, err := os.Create(toFile)
if err != nil {
return
}
defer tofile.Close()
return io.Copy(tofile, fromfile)
}
... |
package sprigmath
import (
"testing"
"github.com/pkg/errors"
)
func testFloat(expected float64, init interface{}, errstr string) error {
v, err := toFloat64(init)
if err = testError(errstr, err); err != nil {
return err
}
if errstr == "" && !floatEquals(v, expected) {
return errors.Errorf("Expected %v, go... |
package utils
import (
"github.com/veandco/go-sdl2/sdl"
"main/types"
)
const (
WINDOW_HEIGHT = 640
WINDOW_WIDTH = 800
WINDOW_DELAY = 4000
)
func DrawCardioid(values []types.CardioidPart) {
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
window, renderer, err := sdl.Cre... |
package util
import (
"fmt"
"time"
"google.golang.org/protobuf/types/known/timestamppb"
)
type Timestamp timestamppb.Timestamp
func (ts *Timestamp) Scan(value interface{}) error {
if ts != nil {
return fmt.Errorf("Can't scan timestamp into nil reference")
}
var t time.Time
var protoTs *timestamppb.Timesta... |
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use ... |
// 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 filepicker supports controlling the file picker on ChromeOS.
package filepicker
import (
"context"
"fmt"
"time"
"chromiumos/tast/errors"
"chromiumos/tast/lo... |
package main
import (
"log"
"net/http"
)
//Run 路由
func Run() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
http.HandleFunc("/", IndexView)
http.HandleFunc("/upload", UploadView)
http.HandleFunc("/list", ListView)
http.HandleFunc("/detail", DetailView)
http.Hand... |
package v7
import (
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/v7/shared"
"code.cloudfoundry.org/cli/util/ui"
"code.cloudfoundry.org/clock"
)
//go:generate counterfeiter . ServiceBrokersActor
t... |
package main
import (
"container/ring"
"fmt"
)
func main() {
const rLen = 3
// 创建新的 Ring
r := ring.New(rLen)
for i := 0; i < rLen; i++ {
r.Value = i
r = r.Next()
}
fmt.Printf("Length of ring: %d\n", r.Len()) // Length of ring: 3
// 该匿名函数用来打印 Ring 中的数据
printRing := func(v interface{}) {
fmt.Print(... |
package mem_test
import (
"bytes"
"encoding/json"
"fmt"
"github.com/ionous/sashimi/_examples/stories"
"github.com/ionous/sashimi/net"
"github.com/ionous/sashimi/net/app"
"github.com/ionous/sashimi/net/ess"
"github.com/ionous/sashimi/net/mem"
"github.com/ionous/sashimi/net/resource"
"github.com/stretchr/testi... |
package main
import (
"fmt"
"os"
)
// Global declarations
func assert(t bool, msg string){
if (!t){
fmt.Fprintf(os.Stderr, msg)
os.Exit(1)
}
}
// Node basic data structure
type Node struct {
Data int
Left *Node
Right *Node
}
// NewNode create a new node reference
func NewNode(data int) *Node {
return &... |
// Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, ... |
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, ... |
package runner
import (
"bytes"
"fmt"
"regexp"
"strings"
"time"
warp "github.com/PierreZ/Warp10Exporter"
jira "github.com/andygrunwald/go-jira"
log "github.com/sirupsen/logrus"
"github.com/ovh/jerem/src/core"
)
const storyPointField = "customfield_10006"
var quarterRegex = regexp.MustCompile(`^Q[1-4]-\d{2... |
package main
import (
"fmt"
"sync"
"time"
)
func hello(i int, wg *sync.WaitGroup) {
fmt.Printf("Goroutine #%d started\n", i)
time.Sleep(2 * time.Second)
fmt.Printf("Goroutine #%d finished\n", i)
wg.Done()
}
func main() {
fmt.Println()
no := 500
var wg sync.WaitGroup
for i := 0; i < no; i++ {
time.Sleep(... |
package store
import (
"github.com/mylxsw/glacier/infra"
)
type Provider struct{}
func (s Provider) Register(app infra.Binder) {
app.MustSingleton(NewEventStore)
}
func (s Provider) Boot(app infra.Resolver) {}
|
package client
import (
"path/filepath"
"strings"
)
// PathKind describes the type of a path
type PathKind int
// types of paths
const (
BACKEND PathKind = iota
NODE
LEAF
NONE
)
func (client *Client) topLevelType(path string) PathKind {
if path == "" {
return BACKEND
} else if _, ok := client.KVBackends[p... |
package codegen
import (
"bytes"
"strings"
"text/template"
)
func JoinWithSpace(a ...string) string {
return strings.Join(a, " ")
}
func JoinWithColon(a ...string) string {
return strings.Join(a, ":")
}
func JoinWithSlash(a ...string) string {
return strings.Join(a, "/")
}
func JoinWithLineBreak(a ...string)... |
package clicolorer
//go:generate counterfeiter -o ./fake.go --fake-name Fake ./ CliColorer
import (
"github.com/fatih/color"
)
type CliColorer interface {
// silently disables coloring
Disable()
// attention colors
Attention(
format string,
values ...interface{},
) string
// errors collors
Error(
for... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.