text stringlengths 11 4.05M |
|---|
package bslib
import (
"database/sql"
"os"
_ "github.com/mattn/go-sqlite3" // Needed to work correctly with database/sql
)
// StorageDB is a class to access all storage functionality
type storageDB struct {
// instance & status
sDB *sql.DB
dbOpen bool
sTX *sql.Tx
// db settings
dbVersion int
dbID ... |
// vi:nu:et:sts=4 ts=4 sw=4
// How to parse html in Golang using the HTML Tokenizer.
//
// Warning: The HTML Tokenizer is a one-pass parser. It is not a tree
// structure that you can do passes over. If you want a tree
// like structure, then you should use html.Parse().
//
// 1/9/2020 - I modifie... |
package dbl
import (
"database/sql"
"errors"
"fmt"
_ "github.com/lib/pq"
"time"
)
type DAO struct {
db *sql.DB
ConnStr string
binDao *BinDao
fileDao *FileDao
infoDao *InfoDao
transactionDao *TransactionDao
}
// Init a database connection given
// a database name an... |
package src
import (
"github.com/barrydev/api-3h-shop/src/common/utils"
"github.com/gin-gonic/gin"
)
type App struct {
instance *gin.Engine
}
func (app *App) NewGinEngine() *gin.Engine {
_app := gin.Default()
_cors := utils.Cors()
_app.Use(_cors)
BindRouterWithApp(_app, []gin.HandlerFunc{_cors})
app.instanc... |
// Package network manages the network services of the application dataplane. This
// means ensuring that containers can find and communicate with each other in accordance
// with the policy specification. It achieves this by manipulating IP addresses and
// hostnames within the containers, Open vSwitch on each runni... |
package amqp_kit
import (
"context"
"testing"
"time"
"github.com/streadway/amqp"
"github.com/stretchr/testify/suite"
)
type apiSuite struct {
suite.Suite
dsn string
conn *amqp.Connection
}
func (s *apiSuite) SetupSuite() {
var err error
s.dsn = MakeDsn(&Config{
Address: "127.0.0.1:5672",
User: "... |
/*
* Copyright © 2019-2022 Software AG, Darmstadt, Germany and/or its licensors
*
* 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://... |
package dto
import (
"fmt"
)
//This structure will be returned by REST API to client.
type RestResponse struct {
Error string `json:",omitempty"`
TaskId int64
Data []Dto
}
func NewRestResponse(err string, taskId int64, data []Dto) *RestResponse {
rr := new(RestResponse)
rr.Error = err
rr.TaskId = taskId
r... |
package redis
import (
"context"
"github.com/go-redis/redis/v8"
)
func GetDB() (client redis.UniversalClient, err error) {
switch RedisConfig.Mode {
case "single":
client = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: RedisConfig.Addr,
Password: RedisConfig.Password,
DB: RedisCon... |
package main
import (
"context"
"io"
"log"
"testing"
"concurrency"
)
var requests = concurrency.GenerateRequests(concurrency.Count)
func init() {
log.SetOutput(io.Discard)
}
func BenchmarkErrGroupPrealloc(b *testing.B) {
for n := 0; n < b.N; n++ {
DoAsync(context.TODO(), requests)
}
}
|
package c44_dsa_repeated_nonce
import (
"bufio"
"bytes"
"crypto/sha1"
"math/big"
"os"
"strings"
"testing"
"github.com/vodafon/cryptopals/set1/c1_hex_to_base64"
"github.com/vodafon/cryptopals/set6/c43_dsa_from_nonce"
)
func TestExploit(t *testing.T) {
texts := loadTexts("./testdata/44.txt")
dsa := c43_dsa_... |
package tsrv
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document01200101 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:tsrv.012.001.01 Document"`
Message *UndertakingTerminationNotificationV01 `xml:"UdrtkgTermntnNtfctn"`
}... |
package pixelproxy
import (
"context"
"fmt"
"net/http"
"os"
"path/filepath"
"sync"
"time"
"github.com/danjacques/pixelproxy/applications/pixelproxy/storage"
"github.com/danjacques/pixelproxy/applications/pixelproxy/web"
"github.com/danjacques/pixelproxy/util"
"github.com/danjacques/pixelproxy/util/logging"... |
// Copyright 2020 PingCAP, 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 dsp
// NewFBCombMS returns a new FBComb
func NewFBCombMS(ms MS) *FBComb {
return &FBComb{dl: NewDelayLineMS(ms)}
}
// FBComb is a feedback comb filter
type FBComb struct {
dl *DelayLine
last Float64
}
// Tick advances the filter's operation with the default duration
func (c *FBComb) Tick(in, gain Float6... |
package mock
import (
"context"
"time"
"github.com/odpf/optimus/job"
"github.com/odpf/optimus/core/tree"
"github.com/google/uuid"
"github.com/odpf/optimus/models"
"github.com/odpf/optimus/store"
"github.com/stretchr/testify/mock"
)
type ReplayRepository struct {
mock.Mock
}
func (repo *ReplayRepository) ... |
package main
import "fmt"
func main() {
var name string
name = "Nabil Fawwaz Elqayyim"
fmt.Println(name)
var name2 = "Nabil"
fmt.Println(name2)
name3 := "Nabil"
fmt.Println(name3)
}
|
package main
import (
"fmt"
"github.com/boltdb/bolt"
"github.com/jordan-wright/email"
"log"
"net"
"strings"
)
type Mail struct {
Body string `json:"-"`
To string `json:"to"`
Id string `json:"id"`
From string `json:"-"`
Subject string `json:"-"`
MessageId string `json:"-"`
}
func... |
//go:build localtest
package uixt
import (
"bytes"
"fmt"
"os"
"testing"
)
func checkOCR(buff *bytes.Buffer) error {
service, err := newVEDEMImageService()
if err != nil {
return err
}
imageResult, err := service.GetImage(buff)
if err != nil {
return err
}
fmt.Println(fmt.Sprintf("imageResult: %v", ima... |
package main
import (
"fmt"
"net/http"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/go-zoo/bone"
"github.com/codegangsta/negroni"
"gorest-xls/random"
"os"
"io/ioutil"
"strconv"
)
func main() {
mux := bone.New()
mux.Get("/api/v1/excel", http.HandlerFunc(ExcelHandler))
n := negroni.C... |
/*
Templates are mainly used to seperate data part and formatting part.
*/
package main
import (
"fmt"
"os"
"text/template"
)
type Entry struct {
Number int
Square int
}
func main() {
arguments := os.Args
if len(arguments) != 2 {
fmt.Println("please provide a required text file")
return
}
tFile := arg... |
package combat
import "math"
//exponent represents the increase of difficulty between levels
//Disgea Level formula to the first 99 levels.
func NextLevel(level int) float64 {
exponent := 1
baseXP := 1000.0
//return math.Round( 0.04 * float64(level ^ 3) + 0.8 * float64(level ^ 2) + float64(2 * level))
return math... |
package middlewares
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/helmet/v2"
)
func SetupMiddleware(app *fiber.App) {
app.Use(helmet.New())
app.Use(recover... |
package repositories
import (
"errors"
"log"
"github.com/jinzhu/gorm"
"github.com/kazetora/evermos-assignment/problem_1_ecommerce/models"
)
func isStockAvailable(db *gorm.DB, productID uint, qty int) (bool, error) {
var inventory models.Inventories
if err := db.Where("product_id = ?", productID).First(&invento... |
package models
import (
"database/sql"
"encoding/json"
"strconv"
// is nedded for sql querys
_ "github.com/lib/pq"
)
// Domain : model for the domain struct
type Domain struct {
ID int `json:"id"`
Domain string `json:"domain"`
Data Response `json:"data"`
}
// DomainCollection : return domain co... |
package main
import (
"strconv"
"encoding/json"
"encoding/gob"
"bytes"
)
const (
ENCODE_TYPE_JSON = "json"
ENCODE_TYPE_GOB = "gob"
)
type User struct {
Id int `json:"id"`
Name string `json:"name"`
Social string `json:"social"`
UserAccount UserAccountInterface `json:"-"`
}
func (u ... |
package leetcode
import (
"reflect"
"sort"
"testing"
)
func TestSubdomainVisits(t *testing.T) {
ans1 := subdomainVisits([]string{"9001 discuss.leetcode.com"})
sort.Strings(ans1)
if !reflect.DeepEqual(ans1,
[]string{
"9001 com",
"9001 discuss.leetcode.com",
"9001 leetcode.com",
}) {
t.Fatal()
}
... |
//OneWire support.
package embd
import (
"log"
"os"
)
// W1Bus interface is used to interact with the OneWire bus.
type W1Bus interface {
// List devices on the bus
ListDevices() (devices []string, err error)
// Open a device
Open(address string) (device W1Device, err error)
// Close releases the resources ... |
package main
// Go Hello World
import "fmt"
func main() {
fmt.Println("\nhello world\n")
}
|
package contract
type BaseRequest struct {
}
type BaseResponse struct {
StatusCode StatusCode `json:"status_code"`
StatusInfo *StatusInfo `json:"status_info"`
}
type StatusInfo struct {
Time int64 `json:"time"`
Message string `json:"message"`
}
type StatusCode int32
const (
SUCCESS StatusCode = 1
FAILUR... |
package email
import (
"github.com/shopspring/decimal"
"time"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/enum"
"github.com/quickfixgo/quickfix/field"
"github.com/quickfixgo/quickfix/fix41"
"github.com/quickfixgo/quickfix/tag"
)
//Email is the fix41 Email type, MsgType = C
type Email stru... |
package internal
import (
"reflect"
"testing"
"github.com/5xxxx/pie/driver"
"go.mongodb.org/mongo-driver/bson"
)
func TestDefaultCondition(t *testing.T) {
tests := []struct {
name string
want driver.Condition
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {... |
package inventoryd
import (
"context"
"encoding/base64"
"errors"
"log"
"strconv"
"strings"
)
// Register時のパラメータ
// OMA-TS-LightweightM2M-V1_0_2-20180209-A 5.3.1参照
// BingindModeはU/UQ/S/SQ/USがあるが、Uしか使わない
const (
lwm2mVersion string = "1.0"
lwm2mBindingMode string = "U"
)
// Register : Register Operation
/... |
package main
import (
"fmt"
)
func main() {
var t int
fmt.Scanf("%d\n", &t)
for i:=0; i<t; i++ {
var w, h, n uint64
fmt.Scanf("%d %d %d\n", &w, &h, &n)
var f uint64
f = 1
for (w % 2 == 0) || (h % 2 == 0) {
f *= 2
if f >= n { break }
if w % 2 == 0 {
w /= 2
}... |
package main
type WordDescription struct {
Tf float64
Idf float64
Rank float64
} |
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2019 Dell, Inc. //
// ... |
package piscine
func BasicJoin(strs []string) string {
//empty string
strJoin := ""
for _, element := range strs {
strJoin = strJoin + element
}
return strJoin
}
|
package relay
import (
"context"
"crypto/tls"
"fmt"
"strings"
"sync"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"github.com/batchcorp/collector-schemas/build/go/protos/services"
"github.com/b... |
package main
import "fmt"
func computePowerSet(nums []int, pos int, setSoFar []int, results [][]int) [][]int {
if pos >= len(nums) {
resultSet := make([]int, len(setSoFar))
copy(resultSet, setSoFar)
return append(results, resultSet)
}
// Case 1: move forward, excluding nums[pos]
tempSetWithoutPos := make([... |
package main
import (
"fmt"
)
//go中的字符串都是采用UTF-8编码,字符串是用一对双引号("")或者反引号(``)括起来的。
//不赋值时,默认为空字符串。
func main() {
var emptyString string = "asdfdf"
fmt.Printf(emptyString)
var s string = "hello"
//在go中字符串是不可变的,如下会报错
// s[0] = 'c'
//如果想改需要转化成byte数组
c := []byte(s) // 将字符串 s 转换为 []byte 类型
c[0] = 'c'
s2 := strin... |
// Copyright 2017 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 quantum
// A CircuitGen generates exhaustive lists of circuits.
//
// It is not safe to call methods on a CircuitGen from
// multiple Goroutines concurrently.
type CircuitGen struct {
numBits int
basis []Gate
hasher CircuitHasher
cache [][]Circuit
cacheRemaining int
}
// ... |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package operations
import (
"testing"
"github.com/Azure/aks-engine/pkg/armhelpers"
. "github.com/Azure/aks-engine/pkg/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
)
f... |
package spec
type AReq struct {
X int `json:"x"`
Y int `json:"y"`
}
type ARes struct {
StatusCode string `json:"statusCode"`
Result int `json:"result"`
}
type LogAReq struct {
LogTime JSONTime `json:"logTime"`
Info string `json:"info"`
Req string `json:"requestBody"`
}
type LogARes struct {... |
package objs
type Configuration struct {
// 시스템
DataRetentionDays int `form:"data_retention_days"`
// 로그인
MaxFailedLoginAttempts int `form:"max_failed_login_attempts"`
LoginFailureBlockTime int `form:"login_failure_block_time"`
}
|
package models
import (
"time"
"github.com/jinzhu/gorm"
)
//Login 登录
type Login struct {
UserName string
Password string
}
//QueryBill 查询流水
type QueryBill struct {
InBill bool //元征账户进账流水
StartTime int64 //开始时间
EndTime int64 //结束时间
}
//IncomeStatement 收入流水
type IncomeStatement struct {
gorm.Model
Ord... |
package engine
import (
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/engine"
)
type State struct {
ReleaseName string
Namespace string
Chrt *chart.Chart
Values chartutil.Values // final values used for rendering
IsUpgrade bool
... |
package routers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context/param"
)
func init() {
beego.GlobalControllerRouter["mall/controllers:CommentController"] = append(beego.GlobalControllerRouter["mall/controllers:CommentController"],
beego.ControllerComments{
Method: "Pos... |
package binarytree
import (
"container/list"
"reflect"
)
type Item interface{}
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func arrayToBinTree(nums []Item) *TreeNode {
queue := list.New()
if reflect.TypeOf(nums[0]) == nil {
return nil
}
root := &TreeNode{nums[0].(int), nil, nil}
q... |
package server
import (
"github.com/hokora/bank/ipc"
"github.com/hokora/bank/util"
)
const (
TRANSFER_ERR_NONE = 0
TRANSFER_ERR_FROM_NOT_EXIST = 1
TRANSFER_ERR_TO_NOT_EXIST = 2
TRANSFER_ERR_SERVER = 3
TRANSFER_ERR_NOT_ENOUGH_BALANCE = 4
)
func (s *Server) TransferHandler(ctx *ipc.Context) {
pr := uti... |
package operatorlister
import (
"fmt"
"sync"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
corev1 "k8s.io/client-go/listers/core/v1"
)
type UnionServiceAccountLister struct {
serviceAccountListers map[string]corev1.Servi... |
package progress
import (
"os"
"gopkg.in/cheggaaa/pb.v1"
)
type Bar struct {
*pb.ProgressBar
}
func NewBar() Bar {
bar := pb.New(0)
bar.SetUnits(pb.U_BYTES)
bar.Output = os.Stderr
return Bar{bar} // shop
}
func (b Bar) SetTotal(contentLength int64) {
b.Total = contentLength
}
func (b Bar) Kickoff() {
b.S... |
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.,
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obt... |
package main
import (
"errors"
"fmt"
)
type Queue struct {
store []int
front int
rear int
size int
}
func NewQueue(size int) *Queue{
return &Queue{make([]int, size), 0, 0, 0}
}
func (q *Queue) isFull() bool {
return len(q.store) == q.size
}
func (q *Queue) enque(num int) error{
if q.size == len(q.store) {
... |
package main
import (
"regexp"
"strings"
"github.com/clipperhouse/inflect"
)
type Type struct {
Package *Package
Pointer string
Name string
StandardMethods []string
Projections []*Projection
Containers []string
Imports []string
}
func (t *Type) LocalName() (resu... |
package v1alpha3
import (
"github.com/devspace-cloud/devspace/pkg/devspace/config/versions/config"
"github.com/devspace-cloud/devspace/pkg/devspace/config/versions/util"
next "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/v1alpha4"
"github.com/devspace-cloud/devspace/pkg/util/log"
)
// Upgrade u... |
package gormsql
import (
"github.com/atymkiv/echo_frame_learning/blog/model"
"github.com/jinzhu/gorm"
)
// NewUser returns a new user database instance
func NewUser(db Database) *User {
return &User{
db: db,
}
}
// User represents the client for user table
type User struct {
db Database
}
// Interface for po... |
package ircserver
import "gopkg.in/sorcix/irc.v2"
func init() {
Commands["server_QUIT"] = &ircCommand{
Func: (*IRCServer).cmdServerQuit,
}
}
func (i *IRCServer) cmdServerQuit(s *Session, reply *Replyctx, msg *irc.Message) {
// No prefix means the server quits the entire session.
if msg.Prefix == nil {
i.dele... |
package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/BurntSushi/toml"
"github.com/fatih/color"
"github/luoyayu/goidx/api"
"github/luoyayu/goidx/config"
"github/luoyayu/goidx/utils"
S "gopkg.in/abiosoft/ishell.v2"
"io"
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
)
v... |
package week11
// 66. 加一 https://leetcode-cn.com/problems/plus-one/
// 输入:digits = [1,2,3]
// 输出:[1,2,4]
func plusOne(digits []int) []int {
ptr := len(digits) - 1
plus := true
for ptr >= 0 {
if digits[ptr] == 9 && plus {
// 如果是9且需要进位, 则数字改为0, 保持进位
digits[ptr] = 0
} else if plus {
// 如果不是9且需要进位, 则数字+1,... |
// Package controlplane contains the HTTP and gRPC base servers and the xDS gRPC implementation for envoy.
package controlplane
import (
"fmt"
"net/http"
"time"
"github.com/CAFxX/httpcompression"
"github.com/gorilla/mux"
"github.com/pomerium/pomerium/config"
"github.com/pomerium/pomerium/internal/handlers"
"... |
// Copyright 2020 PingCAP, 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 "github.com/vugu/vugu"
func vuguSetup(buildEnv *vugu.BuildEnv, eventEnv vugu.EventEnv) vugu.Builder {
var counter Counter
buildEnv.SetWireFunc(func(b vugu.Builder) {
if c, ok := b.(CounterSetter); ok {
c.CounterSet(&counter)
}
})
ret := &Root{}
buildEnv.WireComponent(ret)
return r... |
package definition
import (
"fmt"
"io/ioutil"
"os"
"path"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
const maxDepth = 50
// TemplateRenderer - Interface to user for the template rendering
type TemplateRenderer interface {
Render(templateStr string)
AddOutput(stepName string, varName string, valu... |
package main
import "fmt"
func main() {
var i float32 = 42
fmt.Println("i = ", i)
j := 43
fmt.Println("j = ", j)
sum := i + j
fmt.Println("sum = ", sum)
}
|
package oauth
import (
"bytes"
"context"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"io/ioutil"
"net/http"
"os"
"testing"
"time"
)
var (
host = ""
client = http.Client{Timeout: 5 * time.Second}
)
func Test... |
package main
import (
"fmt"
"time"
)
func main() {
//demand1()
//demand2()
demand3()
fmt.Println("休眠结束")
}
//延时方式一: 休眠
func demand1() {
time.Sleep(time.Second)
}
//延时方式二: Timer
func demand2() {
timer := time.NewTimer(time.Second)
<-timer.C
timer.Stop()
}
//延时方式三: After ~ 和Timer等价
func demand3() {
ch2 :... |
package access
import (
"fmt"
"path"
"sort"
"strconv"
"github.com/databrickslabs/databricks-terraform/common"
"github.com/databrickslabs/databricks-terraform/identity"
"github.com/databrickslabs/databricks-terraform/workspace"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/error... |
/*
Copyright © 2021 Denis Belyatsky <denis.bel@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, ... |
package service_test
import (
"context"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"sort"
"testing"
"github.com/go-ocf/kit/codec/cbor"
"github.com/go-ocf/kit/codec/json"
"github.com/go-ocf/cloud/authorization/provider"
c2cTest "github.com/go-ocf/cloud/cloud2cloud-gateway/test"
"github.com... |
package centos
import (
"errors"
"github.com/caos/orbos/internal/operator/common"
"github.com/caos/orbos/mntr"
"strings"
)
func getEnsureMasquerade(
monitor mntr.Monitor,
zoneName string,
current *common.ZoneDesc,
desired common.Firewall,
) (
string,
error,
) {
ensureMasquerade := ""
masq, err := queryMa... |
package main
import (
"flag"
"log"
"os"
"github.com/janivihervas/authproxy/internal/server"
"github.com/janivihervas/authproxy/upstream"
)
func main() {
var port = "3000"
if e := os.Getenv("PORT"); e != "" {
port = e
}
var portFlag string
flag.StringVar(&portFlag, "port", "3000", "port to run the serve... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//104. Maximum Depth of Binary Tree
//Given a binary tree, find its maximum depth.
//The maximum depth is the number of nodes along the longest path fr... |
package services
import (
"context"
pingv1 "github.com/syncromatics/kafmesh/internal/protos/kafmesh/ping/v1"
)
// PingAPI provides uptime status for the kafmesh service
type PingAPI struct{}
// Ping responses immediately when a request is made
func (s *PingAPI) Ping(ctx context.Context, request *pingv1.PingReques... |
package agrasta
import (
"testing"
"golang.org/x/crypto/sha3"
)
// We have to make sure the rank counting works reliably
func TestMatrixRanker(t *testing.T) {
s := State{}
s.ShakeHash = sha3.NewShake256()
faults := 0
for i := 0; i < 1000; i++ {
// Fill the matrix with random data
var m Matrix
for i := 0;... |
/*
Copyright 2023 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 main
import (
"bytes"
"flag"
"fmt"
)
func getCountFromNum(inputNumber int) int {
num := inputNumber - '0'
if num >= 2 && num <= 6 {
return 3
}
if num == 7 {
return 4
} else if num == 8 {
return 3
} else if num == 9 {
return 4
} else {
return 0
}
}
func getStringFromNum(inputNumber int) ... |
package main
import (
"time"
"github.com/shauncampbell/golang-tplink-hs100/pkg/configuration"
"github.com/shauncampbell/golang-tplink-hs100/pkg/hs100"
)
const defaultSleep = 2000 * time.Millisecond
func main() {
h := hs100.NewHs100("localhost", configuration.Default())
println("Name of device:")
name, _ := h... |
package main
import (
"fmt"
"testing"
"time"
)
func TestPlainTextWithoutTemplate(t *testing.T) {
// given
tmpl := "text-value 123"
tmplCtx := NewTemplateContext(NewVars(""))
// when
output := tmplCtx.ApplyTo(tmpl)
// then
expected := "text-value 123"
if tmplCtx.HasErrors() {
t.Error("Unexpected error"... |
package hot100
import "sort"
// 给你一个整数数组 nums ,其中可能包含重复元素,请你返回该数组所有可能的子集(幂集)。
// 解集 不能 包含重复的子集。返回的解集中,子集可以按 任意顺序 排列。
// 关键: dfs
// 若当前数x之前的数y ,x==y,并且y 之前没有被选中,则当前可以直接退出
func subsetsWithDup(nums []int) [][]int {
sort.Ints(nums)
ret := make([][]int, 0)
var dfs func(chosePre bool, index int)
temp := make([]int, 0)... |
package dictparser
import (
"testing"
"github.com/stretchr/testify/assert"
)
var successTests = []struct {
input string
output []string
}{
{
input: "",
output: []string{},
},
{
input: "aa aa aa bb bb d d d d c",
output: []string{"d", "aa", "bb", "c"},
},
{
input: "a b b c c c d d d d e e e e e... |
package router
import (
"fmt"
"testing"
"time"
"github.com/AsynkronIT/protoactor-go/actor"
"github.com/stretchr/testify/mock"
)
var _ fmt.Formatter
var _ time.Time
func TestRouterSendsUserMessageToChild(t *testing.T) {
child, p := spawnMockProcess("child")
defer removeMockProcess(child)
p.On("SendUserMessa... |
package routers
import (
"github.com/astaxie/beego"
)
func init() {
beego.GlobalControllerRouter["message/controllers:UserController"] = append(beego.GlobalControllerRouter["message/controllers:UserController"],
beego.ControllerComments{
"Signin",
`/signin`,
[]string{"get"},
nil})
beego.GlobalContr... |
package action
import (
"context"
"github.com/guilhermesteves/aclow"
"github.com/guilhermesteves/go-todo-api/pkg/data/config"
dbtransformer "github.com/guilhermesteves/go-todo-api/pkg/data/transformer"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/m... |
package metahelm
import (
"testing"
"gopkg.in/src-d/go-billy.v4/memfs"
)
func TestReadFileSafely(t *testing.T) {
oldmax := fileSizeMaxBytes
defer func() { fileSizeMaxBytes = oldmax }()
fileSizeMaxBytes = 5
mfs := memfs.New()
f, _ := mfs.Create("foo.txt")
f.Write([]byte("1234567890"))
if _, err := readFileSa... |
/*
Utils for basic functions.
*/
package utils
|
package main
import (
"encoding/json"
"net/http"
"reflect"
"strings"
"golang.org/x/net/context"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine/log"
)
// DeleteResponse Structure of returning a delete request.
type DeleteResponse struct {
Key *datastore.Key `json:"key"`
}
// EntityResp... |
// +build OMIT
package sample
import "sync"
//START OMIT
type LockedHolder struct {
sync.Locker
Data map[string]string
}
func MainFunc() string {
holder := &LockedHolder{Data: map[string]string{}}
wg := &sync.WaitGroup{}
wg.Add(2)
lockHelper(holder, wg, func() { holder["foo"] = "bar" })
lockHelper(holder, w... |
package main
/*
这个文件是用来测试write是否按照正常的流程运行的
*/
import "github.com/shiningacg/apicore"
func init() {
apicore.AddHandler(apicore.NewMatcher("/stream", "GET"), func() apicore.Handler {
return &Stream{}
})
}
type Stream struct {
}
func (s *Stream) Handle(conn apicore.Conn) {
conn.SetCode(300)
conn.SetHead("X-Hel... |
package int_tree
import (
"github.com/joeyciechanowicz/letter-combinations/pkg/reader"
"sort"
)
func ToAlphabetIndex(letter rune) int {
return int(letter) - int(ToRune("a"))
}
func ToRune(letter string) rune {
return []rune(letter)[0]
}
var RuneToLetters = map[rune]int {
ToRune("a"): ToAlphabetIndex(ToRune("a"... |
// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/
//
// Modifications copyright 2013 Ernest Micklei. 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 o... |
package scrappers
import (
communityv1alpha1 "github.com/cloudnative-id/community-operator/pkg/apis/community/v1alpha1"
)
type Scrapper interface {
GetName() (string, error)
GetArticles() ([]communityv1alpha1.ArticleSpec, error)
}
|
package main
import (
"bufio"
"errors"
"flag"
"fmt"
"io"
"os"
"runtime"
"runtime/pprof"
"sort"
"github.com/wchargin/tensorboard-data-server/fs"
"github.com/wchargin/tensorboard-data-server/io/logdir"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String... |
package grammar
// import "fmt"
// func main() {
// var arr = [10]int{1, 2}
// fmt.Println(arr[0])
// var m = map[string]string{
// "google": "lolo",
// "baidu": "polo",
// }
// for k, v := range m {
// fmt.Println(k)
// fmt.Println(v)
// }
// var k int = 8
// fmt.Println(k)
// }
|
package db
import (
"time"
"github.com/golang/glog"
)
// 发布信息结构体
type Reflash struct {
Id uint "gorm:PRIMARY KEY"
SubCode string `gorm:"type:text;not null` // 排班编号
UserAddr string "gorm:not null" // 用户地址
CreateTime time.Time "gorm:not null" // 创建时间
... |
package integration_test
import (
"github.com/cloudfoundry/libbuildpack/cutlass"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("pushing a static app with dummy file in root", func() {
var app *cutlass.App
AfterEach(func() {
if app != nil {
app.Destroy()
}
app = nil
})
Befo... |
package pool
import (
"crawler/models"
"sync"
"sync/atomic"
)
type StorageMap map[uint64]*models.Task
type StorageType struct {
mx sync.RWMutex
m StorageMap
index uint64
}
func NewStorage() *StorageType {
return &StorageType{
m: StorageMap{},
index: 0,
}
}
func (s *StorageType) NextIndex() ui... |
package resume
import (
"time"
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/kubectl"
"github.com/devspace-cloud/devspace/pkg/util/log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/pkg/errors"
)
//SpaceResumer can resume a space
type Spac... |
package spiders
// where i defined spider
import (
"github.com/wcong/ants-go/ants/http"
"log"
)
const (
BASE_PARSE_NAME = "base"
SPIDERS_STATUS_INIT = iota
SPIDERS_STATUS_RUNNING
SPIDERS_STATUS_STOP
SPIDERS_BASIC_COOKIE
)
/*
what a spider do
* make start request
* define basic parse func
*/
type Spider s... |
package testdata
import "github.com/shitakemura/myapi/models"
type serviceMock struct{}
func NewServiceMock() *serviceMock {
return &serviceMock{}
}
func (s *serviceMock) PostArticleService(article models.Article) (models.Article, error) {
return articleTestData[1], nil
}
func (s *serviceMock) GetArticleListServ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.