text stringlengths 11 4.05M |
|---|
package model
type User struct {
Id int
Username string `sql:"not null;unique"`
Password string `sql:"-"`
HashedPassword []byte `sql:"-"`
Email string `sql:"not null;unique"`
Firstname string `sql:"-"`
Lastname string `sql:"-"`
DisplayName string
}
func (u User) ... |
package example
var Var = 0
var (
VarA = "a"
VarB = "b"
VarC = "c"
)
var Notype string
var (
Test1 = 0
Test2 int
)
const (
C1 = iota
_
C3
C4
C6 = ""
)
// Const
const Const = 1
var Vartype string
// Mult
const (
ConstA = "a"
// Test
ConstB = "b"
ConstC = "c"
)
// AB
const A, B = 2, 3
var Empty int... |
package tengo
import (
"errors"
"reflect"
"testing"
)
func Test_builtinDelete(t *testing.T) {
type args struct {
args []Object
}
tests := []struct {
name string
args args
want Object
wantErr bool
wantedErr error
target interface{}
}{
//Map
{name: "invalid-arg", args: args{... |
// @Description 发送邮件
// @Author jiangyang
// @Created 2020/11/17 4:12 下午
// Example Config:
// email:
// user:
// pass:
// host: smtp.qq.com
// port: 465
package email
import (
"github.com/sirupsen/logrus"
"gopkg.in/gomail.v2"
)
var cfg *Config
type Config struct {
User string `json:"user" yaml... |
/*
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
distributed under the License is... |
package ionic
import (
"fmt"
"regexp"
"strings"
"github.com/ion-channel/ionic/util"
"github.com/google/uuid"
"github.com/ion-channel/ionic/aliases"
"github.com/ion-channel/tools-golang/spdx"
"github.com/ion-channel/tools-golang/spdxlib"
)
type packageInfo struct {
Name string
Version ... |
/*
Copyright 2017 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, ... |
// Live Collection
package livecoll
|
package handler
import (
"encoding/json"
"log"
"github.com/gin-gonic/gin"
"github.com/Rakhimgaliev/tech-db/project/db"
"github.com/Rakhimgaliev/tech-db/project/models"
"github.com/jackc/pgx"
)
type handler struct {
conn *pgx.ConnPool
}
func NewConnPool(config *pgx.ConnConfig) *handler {
connPoolConfig := p... |
// Copyright 2019 GoAdmin Core Team. All rights reserved.
// Use of this source code is governed by a Apache-2.0 style
// license that can be found in the LICENSE file.
package beego
import (
"bytes"
"errors"
"net/http"
"net/url"
"strings"
"github.com/GoAdminGroup/go-admin/adapter"
gctx "github.com/GoAdminGro... |
package server
import (
"fmt"
"log"
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"time"
"github.com/balchua/balsa/pkg/config"
"github.com/balchua/balsa/pkg/fsm"
rafthandler "github.com/balchua/balsa/pkg/raft"
"github.com/balchua/balsa/pkg/store"
"github.com/gorilla/mux"
"github.com/hashicorp/raft"
r... |
package main
import (
"fmt"
)
type RankT int
const (
Ace = iota
Two
Three
Four
Five
Six
Seven
Eight
Nine
Ten
Jack
Queen
King
LastRank
)
var Ranks = []RankT{
Ace,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}
// Used for sorting
type RankArr []int
func (r Ra... |
package btf
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"os"
"testing"
"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/internal/testutils"
qt "github.com/frankban/quicktest"
)
func vmlinuxSpec(tb testing.TB) *Spec {
tb.Helper()
// /sys/kernel/btf was introduced in 341dfcf8d78e ("btf... |
package main
import (
"bytes"
"encoding/binary"
"fmt"
"math"
"os"
"path/filepath"
"strconv"
"time"
)
//获取当前时间,并格式变换
func GetNowTime() string {
return time.Now().String()
}
//获取当前时间,并格式变换
func GetNowDateTimeAsYYMMDDHHMISS() string {
return string([]byte(GetNowTime())[:len("2015-01-01 12:13:14")])
}
//获取当前日... |
package main
import (
"fmt"
"os"
)
func check(table1 []string, table2 []string, table3 []string) bool {
if (table1[0] == table3[0] && table2[0] == table3[0]) ||
(table1[1] == table3[1] && table2[1] == table3[1]) ||
(table1[2] == table3[2] && table2[2] == table3[2]) ||
(table1[0] == table3[2] && table2[1] == ... |
package run
import (
"os"
"github.com/rs/zerolog/log"
"github.com/saucelabs/saucectl/internal/appstore"
"github.com/saucelabs/saucectl/internal/credentials"
"github.com/saucelabs/saucectl/internal/flags"
"github.com/saucelabs/saucectl/internal/rdc"
"github.com/saucelabs/saucectl/internal/region"
"github.com/s... |
// Copyright 2018 Kuei-chun Chen. All rights reserved.
package sim
import (
"bufio"
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/signal"
"runtime"
"strings"
"sync"
"syscall"
"time"
"github.com/simagix/gox"
anly "github.com/simagix/keyhole/analytics"
"github.com/simagix/keyhole/mdb"
"go.mongodb.org/... |
package services
import (
"proximity/config"
"proximity/repo"
)
// UserInterface ...
type UserInterface interface {
GetAllBadWords(skip int, limit int) ([]string, error)
}
//NewUserService ..
func NewUserService(conf config.IConfig, userDb repo.UserRepoInterface) CmsInterface {
return &Cms{config: conf, user: us... |
package main
import "fmt"
// 用two point,头尾指针也可以
func twoSum(nums []int, target int) []int {
for i, v := range nums {
if ii := searchLast(nums, target-v); ii != -1 {
return []int{1+i, 1+ii}
}
}
return []int{-1,-1}
}
func searchLast(nums []int, target int) int {
low, high := ... |
/*
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 logger
import (
"fmt"
"log"
"os"
)
//INITIALIZING LOG FOR SUCCESS
func Success(file *os.File) *log.Logger {
LogSucc := log.New(file, "SUCCESS: ", log.Ldate|log.Ltime|log.Lshortfile)
return LogSucc
}
//INITIALIZING LOG FOR FAILURE
func Failure(file *os.File) *log.Logger {
LogFail := log.New(file, "ERROR... |
package main
import "fmt"
func RetriveData(c chan int) {
for {
if v, ok := <-c; ok {
fmt.Printf("cur value is %v\n", v)
} else {
fmt.Printf("chan is already closed.\n")
goto end
}
}
end:
fmt.Printf("over\n")
}
func AddData(c chan int) {
for _, i := range []int{1, 2, 3} {
if i > 2 {
close(c)... |
package raft
import (
"fmt"
"log"
)
func init() {
log.SetFlags(log.Ltime | log.Lmicroseconds)
}
const debugging = false
func serverDPrint(id int, state raftServerState, source string, format string, args ...interface{}) {
if !debugging {
return
}
allArgs := append([]interface{}{id, state, source}, args...)
... |
package main
import "testing"
func TestSolve(t *testing.T) {
var cases = []struct {
n int
m int
out int64
}{
{2, 2, 3},
{3, 2, 7},
{2, 3, 9},
{2, 4, 27},
{4, 4, 3375},
}
for _, c := range cases {
if out := Solve(c.n, c.m); out != c.out {
t.Errorf("Solve(%v, %v)=%v, expected %v", c.n, c.m,... |
/*****************************************************************
* Copyright©,2020-2022, email: 279197148@qq.com
* Version: 1.0.0
* @Author: yangtxiang
* @Date: 2020-08-20 15:45
* Description:
*****************************************************************/
package pdl
import "io"
type FileExport interface {
Be... |
package node
import (
"encoding/json"
"fmt"
com "github.com/hyperorchidlab/go-miner-pool/common"
"golang.org/x/crypto/ssh/terminal"
"io/ioutil"
"os"
"os/user"
"path/filepath"
)
type PathConf struct {
WalletPath string
DBPath string
LogPath string
PidPath string
ConfPath string
}
type Conf st... |
package collector
import (
"context"
"fmt"
"github.com/jenningsloy318/panos_exporter/panos"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
//"net/url"
)
var (
GlobalCounterSubsystem = "global_counter"
GlobalCounterLabelNames = []string{"category", "aspect", "severity", "... |
package spider
import (
"github.com/yino/AgentSpider/po"
)
func TimerSyncSpider(){
po.InitDB()
exec := NewGetDataSpider("https://www.89ip.cn/index_2.html", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36")
pageSize := 185
exec.GetList(in... |
package main
import (
"fmt"
"log"
"net/http"
)
type myHandler struct {
}
func NewMyHandler() myHandler {
return myHandler{}
}
func (m myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "hello world, request method: %v", r.Method)
}
func main() {
port :... |
package pg
import (
"github.com/kyleconroy/sqlc/internal/sql/ast"
)
type CreateEnumStmt struct {
TypeName *ast.List
Vals *ast.List
}
func (n *CreateEnumStmt) Pos() int {
return 0
}
|
package transport
import "github.com/shijuvar/gokit-examples/services/account"
type (
CreateCustomerRequest struct {
Customer account.Customer
}
CreateCustomerResponse struct {
Err error
}
AddMoneyToWalletRequest struct {
CustomerID string
Amount float64
}
AddMoneyToWalletResponse struct {
Err er... |
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"regexp"
"strings"
"syscall"
"time"
rpc "github.com/hekmon/transmissionrpc"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/multierr"
"github.com/danielmmetz/autoplex/pkg/extract"
"github.co... |
package iterations
import (
"fmt"
"strings"
"testing"
)
func TestRepeat(t *testing.T) {
repetitionsNumber := 6
testChar := "a"
repetitions := Repeat(testChar, repetitionsNumber)
expected := strings.Repeat(testChar, repetitionsNumber)
if repetitions != expected {
t.Errorf("Expected: %s, but received: %s", e... |
package main
import (
"flag"
"fmt"
"os"
"github.com/BurntSushi/toml"
"github.com/appconf/appconf"
//注册storage驱动
_ "github.com/appconf/storage/redis"
)
func cfgParser(filename string) (cfg appconf.Config, err error) {
_, err = toml.DecodeFile(filename, &cfg)
return
}
func exit(err error) {
fmt.Fprintf(os.... |
package main
import "fmt"
type ErrNegativeSqrt struct {
What float64
}
func (e *ErrNegativeSqrt) Error() string {
return fmt.Sprintf("Cannot sqrt negative number : %v", e.What)
}
func run(x float64) error {
return &ErrNegativeSqrt{
x,
}
}
func main() {
fmt.Println(Sqrt(2))
fmt.Println(Sqrt(-2))
}
//Get sq... |
package main
import (
"fmt"
"log"
"net/http"
)
func HelloServer(w http.ResponseWriter, req *http.Request) {
fmt.Println("Inside HelloServer hanndler")
fmt.Fprintf(w, "Hello,"+req.URL.Path[1:]) // 去掉前面的斜杠
}
func main() {
http.HandleFunc("/", HelloServer)
log.Fatal(http.ListenAndServe(":9527", nil))
}
|
package main
import "fmt"
const (
RED = 0
GREEN = 1
BLUE = 2
)
func min2(a, b int) int {
if a < b {
return a
}
return b
}
func min3(a, b, c int) int {
return min2(a, min2(b, c))
}
func calcMinAt(at int, withColor int, costs [][]int, minCosts [][]int) {
if at >= len(costs) {
return
}
if at == len... |
package utils
import (
"github.com/aws/aws-lambda-go/events"
)
// Creates an ApiGatewayProxyResponse with CORS headers based on the given status code and marshalled json body
func CreateResponse(status int, body string) (events.APIGatewayProxyResponse, error) {
// Cloudflare - We support the GET, POST, HEAD, and OP... |
package wire
import (
"bytes"
"io"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gx/ipfs/QmU44KWVkSHno7sNDTeUcL4FBgxgoidkFuTUyTXWJPXXFJ/quic-go/internal/protocol"
"gx/ipfs/QmU44KWVkSHno7sNDTeUcL4FBgxgoidkFuTUyTXWJPXXFJ/quic-go/qerr"
)
var _ = Describe("CONNECTION_CLOSE Frame", func() {
Context("when ... |
package main
import "fmt"
var quine = `package main
import "fmt"
var quine =
var quote = string(96)
func main() {
fmt.Println(quine[:40] + quote + quine + quote + "\n" + quine[41:])
}`
var quote = string(96)
func main() {
fmt.Println(quine[:40] + quote + quine + quote + "\n" + quine[41:])
}
|
package actions
import (
"database/sql"
"errors"
"github.com/barrydev/api-3h-shop/src/common/connect"
"github.com/barrydev/api-3h-shop/src/factories"
"github.com/barrydev/api-3h-shop/src/model"
"strings"
)
func UpdateCategory(categoryId int64, body *model.BodyCategory) (*model.Category, error) {
queryString :=... |
package sync
import (
"bitbucket.org/avanz/anotherPomodoro/common"
"bitbucket.org/avanz/anotherPomodoro/repository"
"bufio"
"encoding/json"
"fmt"
"net"
"strconv"
"strings"
"time"
)
type Listener struct {
repository repository.IPomodoroRepository
sharedAddress string
sharedPort int
}
type IListener ... |
package chats
import "websocket_chat/store/message"
var (
broadcast = make(chan message.Message)
)
|
// Copyright 2018 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 server
import (
"machinedetector/mdpb"
"github.com/golang/protobuf/proto"
"github.com/garyburd/redigo/redis"
"github.com/golang/glog"
"io/ioutil"
"os"
"fmt"
"strconv"
"strings"
"time"
)
var redisIndex int = 0
func GetHosts(mc *RedisConn, bc *RedisConn, dbname string) ([]string, error) {
hostlistk... |
package shttp
import (
"log"
"net/http"
"sync/atomic"
"unsafe"
)
func NewAuthMux(login, pass string) *AuthMux {
return &AuthMux{
*http.NewServeMux(),
&login,
&pass,
}
}
type AuthMux struct {
http.ServeMux
login, pass *string
}
func (m *AuthMux) ChangeCreds(login, pass string) {
atomic.SwapPointer((*... |
package blog
import (
"github.com/jinzhu/gorm"
"mingchuan.me/api"
"mingchuan.me/pkg/morloop"
)
const (
BlogServiceVersion = 3
MaxTitleChars = 120
MaxArticleChars = 120000
)
type mRouter = *morloop.Router
type BlogValidations struct {
MaxTitleChars uint32
MaxArticleChars uint32
}
// BlogService - ... |
package log
import (
"net"
"net/http"
"time"
"github.com/rs/zerolog"
"github.com/pomerium/pomerium/internal/middleware/responsewriter"
"github.com/pomerium/pomerium/internal/telemetry/requestid"
)
// NewHandler injects log into requests context.
func NewHandler(getLogger func() *zerolog.Logger) func(http.Hand... |
/*
* Copyright 2018, CS Systemes d'Information, http://www.c-s.fr
*
* 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 requir... |
package config
import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
const ExchangeURLEnvvarName = "HZN_EXCHANGE_URL"
const FileSyncServiceCSSURLEnvvarName = "HZN_FSS_CSSURL"
type HorizonConfig struct {
Edge Config
AgreementBot AGConfig
Collaborators Collaborators
ArchSynonyms A... |
package datastruct
import (
"errors"
"github.com/MintegralTech/juno/document"
)
type Slice []*Element
func (s Slice) Iterator() *SliceIterator {
return &SliceIterator{index: 0, data: &s}
}
func (s Slice) Len() int {
return len(s)
}
func NewSlice() *Slice {
return &Slice{}
}
func (s *Slice) Add(id document.Do... |
package create
import (
"github.com/spf13/cobra"
"github.com/makkes/gitlab-cli/api"
"github.com/makkes/gitlab-cli/cmd/create/accesstoken"
createproj "github.com/makkes/gitlab-cli/cmd/create/project"
"github.com/makkes/gitlab-cli/cmd/create/vars"
"github.com/makkes/gitlab-cli/config"
)
func NewCommand(client ap... |
// +build linux
package extract
func DocToTxt(filePath string)string{
return ""
}
|
package kcpNetwork
import (
"context"
"fmt"
"github.com/xtaci/kcp-go/v5"
"github.com/yaice-rx/yaice/log"
"github.com/yaice-rx/yaice/network"
"go.uber.org/zap"
"time"
)
type KCPClient struct {
type_ network.ServeType
dialRetriesCount int32
address string
conn network.IConn
p... |
package main
import (
"fmt"
"time"
)
// Timers represent a single event in the future. You tell the timer how long you want to wait, and it provides a channel that will be notified at that time.
func main() {
timer1 := time.NewTimer(2 * time.Second)
// Channell of timer = C
<-timer1.C
fmt.Println("Timer 1 fir... |
package controller
import (
"encoding/json"
"log"
"net/http"
"ocg-be/models"
"ocg-be/repositories"
"ocg-be/util"
"strconv"
"github.com/gorilla/mux"
)
var productStorage *repositories.ProductStorage
var productCollection *repositories.RequestGetProductByCollectionId
func GetProducts(w http.ResponseWriter, r ... |
package cache
import (
"testing"
"fmt"
"hub000.xindong.com/rookie/rookie-framework/protobuf"
)
func TestCacheHandler(t *testing.T) {
OnInit()
cache := NewRedisCache(RedisConfig{RedisAddr:"172.26.163.124:6379" , RedisPassword:"ztjztj120" , RedisDB:0})
cache.StartConnection()
Module.RegistCache("base" , cache)
... |
package sys
import (
"os"
"syscall"
"testing"
"github.com/cilium/ebpf/internal/unix"
qt "github.com/frankban/quicktest"
)
func init() {
// Free up fd 0 for TestFD.
stdin, err := unix.FcntlInt(os.Stdin.Fd(), unix.F_DUPFD_CLOEXEC, 1)
if err != nil {
panic(err)
}
old := os.Stdin
os.Stdin = os.NewFile(uint... |
package main
import (
"fmt"
"github.com/priyendra/golang-euler/common"
)
func pow(a, b int) int {
answer := 1
for i := 0; i < b; i++ {
answer *= a
}
return answer
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func allPrimesUpTo(n int) []int {
answer := []int{2}
for i := 3; i <= n; i++ ... |
package orm
import "testing"
func TestBuildUpdate(t *testing.T) {
_, got := BuildUpdate("", nil)
want := "table can't be empty"
if got != nil && got.Error() != want {
t.Errorf("got %q; want %q", got, want)
}
_, got2 := BuildUpdate("user", nil)
want2 := "columns can't be nil"
if got2 != nil && got2.Error() !... |
package basic
import "fmt"
/*
new([]int) 之后的 list 是一个 *[]int 类型的指针,
不能对指针执行 append 操作。可以使用 make() 初始化之后再用。
同样的,map 和 channel 建议使用 make() 或字面量的方式初始化,不要用 new() 。
所以下面代码不能编译通过
func list1(){
list := new([]int)
list = append(list, 1)
fmt.Println(list)
}
*/
func array() {
arr := [...]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
... |
/**
* Copyright (c) 2018 ZTE Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and the Apache License 2.0 which both accompany this distribution,
* and are available at http://www.eclipse.org/legal/epl-v10.html
... |
package constants
type Response struct {
Response int
Message interface{}
}
|
package local
import (
"testing"
)
func TestCalculateShard(t *testing.T) {
tests := []struct {
size int
shard int
shards int
start int
count int
}{
{22, 1, 10, 0, 3},
{22, 2, 10, 3, 3},
{22, 3, 10, 6, 2},
{29, 10, 10, 27, 2},
{2, 1, 6, 0, 1}, // more shards than elements
{2, 2, 6, 1, 1},... |
// Copyright © 2017 Aeneas Rekkas <aeneas+oss@aeneas.io>
//
// 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... |
// This program demonstrates how to attach an eBPF program to a uretprobe.
// The program will be attached to the 'readline' symbol in the binary '/bin/bash' and print out
// the line which 'readline' functions returns to the caller.
//go:build amd64
package main
import (
"bytes"
"encoding/binary"
"errors"
"log"... |
package proto
const (
MSG_PUB_BATCH = 'a'
MSG_PUB_ONE = 'b'
MSG_PUB_TIMER = 'c'
MSG_PUB_TIMER_ACK = 'd'
MSG_PUB_RESTORE = 'e'
MSG_SUB = 'f'
MSG_SUBACK = 'g'
MSG_UNSUB = 'h'
MSG_PING = 'i'
MSG_PONG = 'j'
MSG_COUNT = 'k'
MSG_PULL = 'l'
MSG_CONNECT = 'm'
MSG_CONNECT_OK = 'n'
MS... |
package server
import (
"net/http"
"log"
)
func Start(addr string) {
http.HandleFunc("/crawl", handleCrawl)
http.HandleFunc("/wallpager", handleWallPager)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatal(err)
}
}
|
package main
import (
//"github.com/gin-gonic/gin"
//"io"
"io/ioutil"
//"github.com/go-martini/martini"
"encoding/json"
"log"
"net/http"
)
type Results struct {
elements []Elements `json:"elements"`
}
type Elements struct {
denominator int32 `json:"denominator"`
numerator int32 `json:"numerator"`
na... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//407. Trapping Rain Water II
//Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the... |
package controllers
import (
"github.com/astaxie/beego"
"nepliteApi/models"
"github.com/astaxie/beego/logs"
"encoding/json"
"nepliteApi/comm"
)
type SomeNewsController struct {
beego.Controller
}
func (someNewObj *SomeNewsController) GetAll() {
result := comm.Result{Ret: map[string]interface{}{"err": "aaa", "... |
package main
import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"strings"
"time"
"github.com/goburrow/modbus"
"github.com/nsqio/go-nsq"
"github.com/olebedev/config"
)
var (
allData = make(map[string]float64)
config_nsq = nsq.NewConfig()
)
func set(key string, value float64) {
allData... |
package heap
import "testing"
func TestHeap(t *testing.T) {
heap := NewHeap()
heap.Push(3)
t.Log(heap.Top())
heap.Push(4)
t.Log(heap.Top())
heap.Push(2)
t.Log(heap.Top())
heap.Pop()
t.Log(heap.Top())
heap.Pop()
t.Log(heap.Top())
}
|
package pacit
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"net"
)
const (
IP_ICMP = 0x01
IP_TCP = 0x06
IP_UDP = 0x11
IP_IPv6 = 0x29
IP_IPv6ICMP = 0x3a
)
type IPv4 struct {
Version uint8 //4-bits
IHL uint8 //4-bits
DSCP uint8 //6-bits
ECN uint8 ... |
// Copyright 2021 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... |
/*
Tencent is pleased to support the open source community by making Basic Service Configuration Platform 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 obtain... |
package controllers
import (
"github.com/astaxie/beego"
)
type DefaultController struct {
beego.Controller
}
func (this *DefaultController) Get() {
this.Ctx.WriteString("GoGameServer: hello world")
}
|
package parser
import (
"unicode"
"unicode/utf8"
)
func lexReference(l *StatefulRubyLexer) stateFn {
l.acceptRun(alphaNumericUnderscore + "!")
switch l.input[l.start:l.pos] {
case "def":
l.emit(tokenTypeDEF)
case "do":
l.emit(tokenTypeDO)
case "end":
l.emit(tokenTypeEND)
case "if":
l.emit(tokenTypeIF... |
package main
import (
"sync"
)
type ThreadPool struct {
available chan struct{}
size int
group sync.WaitGroup
}
func NewThreadPool(size int) *ThreadPool {
available := make(chan struct{}, size)
for i := 0; i < size; i++ {
available <- struct{}{}
}
return &ThreadPool{
group: sync.WaitGroup{}... |
// Copyright 2014 Gyepi Sam. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package redux
// NullDb is a blackhole database, used for source files outside the redo project directory structure..
// It never fails, all writes disappear, and r... |
package _020_10_20
func permute(nums []int) [][]int {
n := len(nums)
res := make([][]int, 0)
out := make([]int, n)
for i, v := range nums {
out[i] = v
}
backtrack(0, n, out, &res)
return res
}
func backtrack(first int, n int, out []int, res *[][]int) {
if first == n {
*res = append(*res, append([]int{}, o... |
package controller
import (
"context"
"encoding/json"
"strings"
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controll... |
// time: o(n), space: o(n)
func subarraySum(nums []int, k int) int {
m := make(map[int]int)
m[0] = 1
res := 0
sum := 0
for _, n := range nums {
sum += n
if i, ok := m[sum-k]; ok {
res += i
}
m[sum] += 1
}
return res
}
|
package parser
import (
"github.com/robfig/cron/v3"
)
// Parser is a cron parser
type Parser struct {
parser cron.Parser
}
// NewParser creates an Parser instance
func NewParser() cron.ScheduleParser {
return Parser{cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Des... |
package main
import "fmt"
func main0901() {
//初始化
s:= []int{10,20,30,40,50}
fmt.Println(cap(s))
//截取 s[low:high:max]
//len = high-low
//cap = max -low
//slice := s[:]
//slice := s
slice := s[2:]
fmt.Println(slice)
fmt.Println(len(slice))
fmt.Println(cap(slice))
}
func main() {
s := []int{0,1,2,3,4,5,6,... |
// Copyright 2023 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 leetcode
/*A valid parentheses string is either empty (""), "(" + A + ")", or A + B,
where A and B are valid parentheses strings, and + represents string concatenation.
For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
A valid parentheses string S is primitive if it is nonem... |
package modules
import (
"sort"
)
type SearchResult struct {
Results []string
}
func (searchResult *SearchResult) Sorted() []string {
sort.Strings(searchResult.Results)
return searchResult.Results
}
func (searchResult *SearchResult) Append(result string) {
searchResult.Results = append(searchResult.Results, re... |
//go:generate reform
package front
import "github.com/empirefox/reform"
//reform:cc_cart
type CartItem struct {
ID uint `reform:"id,pk"`
CreatedAt int64 `reform:"created_at"`
UserID uint `reform:"user_id" json:"-"`
Name string `reform:"name"`
Img string `reform:"img"`
Type string ... |
package main
import "github.com/urfave/cli"
func application() *cli.App {
a := &cli.App{
Name: "Discord AniHouse server Bot",
Description: "Discord AniHouse server Bot",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "d, debug",
Usage: "Enable debug mode",
},
&cli.StringFlag{
Name: "c, c... |
package sudoku
import (
"container/heap"
"fmt"
"runtime"
"strconv"
"sync"
)
/*
* A CompoundSolveStep is a series of 0 or more PrecursorSteps that are cull
* steps (as opposed to fill steps), terminated with a single, non-optional
* fill step. This organization reflects the observation that cull steps are
* o... |
// Copyright 2023 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... |
//go:generate protoc -I../proto --go_out=plugins=grpc:../proto ../proto/echo.proto
//go:generate protoc -I../proto --swagger_out=logtostderr=true:../proto ../proto/echo.proto
package main
import (
"bytes"
"context"
"flag"
"fmt"
"log"
"net"
"os"
pb "github.com/ginuerzh/echo/proto"
svc1 "github.com/ginuerzh/s... |
package gojson
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
// Unmarshal has no documentation
func Unmarshal(data []byte, v interface{}) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return &json.InvalidUnmarshalError{Type: reflect.TypeOf(v)}
}
dec := new(decoder)
ret... |
// Copyright 2021 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... |
package main
import (
"auth/security"
"auth/user"
"encoding/json"
"log"
"net/http"
"os"
"time"
"github.com/codegangsta/negroni"
"github.com/gorilla/context"
"github.com/gorilla/mux"
)
func main() {
uService := user.NewService()
r := mux.NewRouter()
//handlers
n := negroni.New(
negroni.NewLogger(),
)... |
package gadk
import (
"testing"
)
const apiServer = "http://78.46.250.88:15555"
var (
seed Trytes = "VOQHWAPIKQNYQZRYRMJIYSLPBVLFOTPJMQKKNYDANFTG9ICYDLRUJPCDDWDLD9YEGIKISSHWWHKOWONMN"
)
// TODO Fix
func TestTransfer1(t *testing.T) {
var err error
var adr Address
var adrs []Address
for i := 0; i < 5; i++ {
a... |
package main
import (
"fmt"
"sort"
)
func main() {
var arr [3]int
fmt.Printf("%v - %T", arr, arr)
arrChange(arr, 1, 100)
fmt.Println()
fmt.Printf("%v - %T", arr, arr)
fmt.Println()
var s1 []int
fmt.Printf("%v - %T", s1, s1)
fmt.Println()
fmt.Printf("is s1 is a nil? %v", s1 == nil)
fmt.Println()
fmt.Pr... |
package command
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/markbates/inflect"
"github.com/mattn/echo-scaffold/template"
)
// ModelCommand generates files related to model.
type ModelCommand struct {
PackageName string
ModelName string
ModelNamePlural string
Instanc... |
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/getlantern/systray"
"github.com/op/go-logging"
"net"
"net/http"
"time"
)
const binanceSource = "binance"
const coincapSource = "coincap"
type Token struct {
ID string `json:"id"`
Symbol string `json:"symbo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.