text stringlengths 11 4.05M |
|---|
package sgfw
import (
"fmt"
"strconv"
"strings"
"sync"
// "encoding/binary"
// nfnetlink "github.com/subgraph/go-nfnetlink"
"github.com/google/gopacket/layers"
nfqueue "github.com/subgraph/go-nfnetlink/nfqueue"
"github.com/subgraph/go-procsnitch"
"net"
"os"
"syscall"
"unsafe"
)
var _interpreters = []st... |
package entry
type LevelCfgCache interface {
//GetExpToNextLevel(nowLevel int32) (int32, bool)
GetExpArr() []int32
}
|
package controllers
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/gin-gonic/gin"
"log"
"net/http"
"test/pkg/middleware"
"test/src/constant"
)
func init(){
gin.SetMode(gin.DebugMode) //全局设置环境,此为开发环境,线上环境为gin.ReleaseMode
if _, err := toml.DecodeFile("conf/config.toml", &constant.Config); err != nil {... |
package proto
import (
"packet"
)
type AckScenePlayers struct {
players []*MsgScenePlayer
}
func AckScenePlayersDecode(pack *packet.Packet) *AckScenePlayers {
ackScenePlayers := &AckScenePlayers{}
playersCount := pack.ReadUint16()
for ;playersCount > 0; playersCount-- {
ackSce... |
// Package line implements the Messenger handler of LINE for Telepathy framework.
// Needed configs:
// - SECRET: Channel scecret of LINE Messenging API
// - TOKEN: Channel access token of LINE Messenging API
package line
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"gitlab.com/kavenc/telep... |
package main
func main() {
// 用字面量初始化数组、slice 和 map 时,最好是在每个元素后面加上逗号,即使 是声明在一行或者多行都不会出错。
x := []int{
1,
2
}
_ = x
} |
package model
type GetCart struct {
User User
Product []Product
}
|
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package logs
import (
"context"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/systemlogs"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&te... |
package cmd
import (
"github.com/spf13/cobra"
"github.com/MichaelDarr/ahab/internal"
ahab "github.com/MichaelDarr/ahab/pkg"
)
var cmdCmd = &cobra.Command{
Use: "cmd",
Short: "Execute an attached command in the container",
Run: func(cmd *cobra.Command, args []string) {
helpRequested, err := internal.PrintDo... |
package BlackJack
import "testing"
func TestPlayerScoreEquals21(t *testing.T) {
expectedResult := 21
if Score(10,11) == expectedResult {
if Winner() != 1 {
t.Errorf("Expected the result to be %d, but got %d", expectedResult, Score(10,11))
}
}
}
func TestPlayersTwoCardsGeneration(t *testing.T) {
var ... |
package parser
import (
"fmt"
"testing"
"../ast"
"../lexer"
)
func TestAsStatements(t *testing.T) {
input := `
as x = 5;
as y = 10;
as z = 895678;
`
// Initialize a lexer, parser and a program.
lex := lexer.New(input)
par := New(lex)
program := par.Parse()
checkParseErrors(t, par)
if program == nil ... |
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
var nowFunc = time.Now //for testing
var db *sql.DB
func init() {
db, _ = sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/test?charset=utf8")
}
type ConnPool struct {
//dial is an application supplied function for creating a... |
// +build !windows
package os
import (
"fmt"
"syscall"
"github.com/shirou/gopsutil/process"
log "github.com/sirupsen/logrus"
)
// KillTree sends signal to whole process tree, starting from given pid as root.
// Order of signalling in process tree is undefined.
func KillTree(signal syscall.Signal, pid int32) err... |
//go:generate statik -src=./data
package holidays
import (
"encoding/json"
"os"
_ "github.com/bastengao/chinese-holidays-go/holidays/statik" // load data
"github.com/rakyll/statik/fs"
)
func loadData() ([]event, error) {
statikFS, err := fs.New()
if err != nil {
return nil, err
}
var events []event
err = ... |
package aesencryptor_test
import (
"encoding/base64"
"testing"
"github.com/spotlight21c/aesencryptor"
)
func TestEncrypt(t *testing.T) {
tables := map[string]string{
"This-is-plain-text": "ACFbo72am8SBFGTHgiUlDygR1jYdLLrCWPeFJ2BlyRU=",
}
key := "1234567890abcdef"
for plain, result := range tables {
encV... |
package lib
import (
"fmt"
"github.com/jinzhu/gorm"
_ "gorm.io/driver/mysql"
"os"
)
var (
db *gorm.DB
err error
)
func InitDb() {
db, err = gorm.Open("mysql", "root:root@/realtime?charset=utf8&parseTime=True&loc=Local")
if err != nil {
fmt.Println("连接数据库失败,请检查参数:", err)
os.Exit(1)
}
}
func DBConn() *g... |
package main
import (
//"strconv"
"sort"
"strings"
"sync"
"fmt"
)
// SingleHash: crc32(data)+"~"+crc32(md5(data))
func SingleHash(in, out chan interface{}) {
mutex := &sync.Mutex{}
wgSH := &sync.WaitGroup{}
for inputRaw := range in { // получаем дату из канала in
data := fmt.Sprin... |
package cmd
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"path"
"strings"
)
type RootCmd struct {
Cmd *cobra.Command
//flags
CfgFile string
envPrefix string
}
func (c RootCmd) GetCmd() *cobra.Command {
return c.Cmd
}
func New... |
package router
import (
"github.com/KashEight/not/router/api"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func Init(engine *gin.Engine, db *gorm.DB) {
api.Init(engine, db)
}
|
// Copyright (C) 2019-2020 Zilliz. 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 l... |
package main
import (
"fmt"
"io/ioutil"
"strings"
)
// traceRoute is essentially getDepth. I originally intended to make changes, but didn't.
// It returns an integer representing body's depth.
func traceRoute(depth map[string]int, body string, relationships [][]string) int {
if _, ok := depth[body]; !ok {
for ... |
package parsers
import (
"bufio"
. "github.com/ruxton/tracklist_parsers/data"
"github.com/ruxton/term"
"io"
"os"
"strings"
)
func ParseVirtualDJTracklist(bufReader *bufio.Reader) []Track {
var list []Track
for line, _, err := bufReader.ReadLine(); err != io.EOF; line, _, err = bufReader.ReadLine() {
data :... |
package main
import "fmt"
func playGame(name string) {
name = "ysatnaf"
}
func changeName(name *string) {
*name = "nanoo"
}
func main() {
name := "ysatnaf"
fmt.Println("昵称:", name)
playGame(name)
fmt.Println("游戏昵称:", name)
changeName(&name)
fmt.Println("改名后:", name)
fmt.Println("你家住哪:", &name)
}
|
package main
import "fmt"
func main() {
foo()
func() {
fmt.Println("No args Anonymous says 'Wonderful Wednesday'")
}() // END func no args
func(x int) {
fmt.Println("I have an arg, the meaning of life is ", x)
}(51) // END func with arg
} // END main
func foo() {
fmt.Println("Inside of foo")
}
/... |
package main
import fmt "fmt"
func main() {
array := make([]int, 40)
test := create(array)
pop := 0
fmt.Println("Inserting 6")
test.insert(6)
test.print()
fmt.Println("Inserting 8")
test.insert(8)
test.print()
fmt.Println("Inserting 20")
test.insert(20)
test.print()
fmt.Println("Inserting 11")... |
package utils
import (
"../../config"
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
)
type PackageJsonRequired struct {
Main string `json:"main"`
Scripts struct {
Start string `json:"start"`
Build string `json:"build"`
} `json:"scripts"`
}
func VerifyPackageJson(fp... |
package controllers_test
import (
"os"
"tax-calculator/boot"
"testing"
)
func TestMain(m *testing.M) {
os.Chdir("../")
boot.Bootstrap()
os.Exit(m.Run())
}
|
package parser
import (
"testing"
"github.com/tombuildsstuff/teamcity-go-test-json/models"
)
func TestNoTests(t *testing.T) {
lines := []string{
`Hello`,
`World`,
}
results := testParser(lines)
if len(results) != 0 {
t.Fatalf("Expected no results for junk data but got %d", len(results))
}
}
func TestSi... |
package main
/*
func (___Vun *_TudpNodeSt) _FudpNode__540211x__gap() {
if 0 == ___Vun.unLoopGap {
return
}
___Vun.unCBrece = _FudpNode__540211z__receiveCallBack_withTimeGap
if nil == ___Vun.unCBgap {
go _FudpNode__540211y__gap_default(___Vun)
} else {
go ___Vun.unCBgap(___Vun)
}
}
func _FudpNode__540211... |
package client
import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"github.com/golang/protobuf/proto"
)
type Client struct {
host string
port int
packetsStream *PacketStream
channels []*Channel
}
func NewClient(host string, port int) (*Client, error) {
c := &Client{
host: host,
po... |
package create_token
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"context"
"fmt"
"io/ioutil"
"strings"
"bytes"
"time"
)
var PathTemplate = "/api/v1/token"
func DecodeCreateTokenRequest(_ context.Context, r *http.Request) (interface{}, error) {
body, _ := ioutil.ReadAll(r.Body)
bodyReade... |
package hugo
import (
"github.com/go-cmd/cmd"
"github.com/naoina/toml"
"github.com/pkg/errors"
"github.com/qiaogw/pkg/logs"
"github.com/qiaogw/pkg/tools"
"os"
"path/filepath"
)
//var (
// hugoConfig = config.Config.Hugo
//)
//func GetHugoConfig() *Config {
// return &hugoConfig
//}
func NewHugo() *SiteConfig... |
package authentication
// Token it's the token representation from the auth0 authentication api
// https://auth0.com/docs/api/authentication#get-token
// It's a dynamic object since it has multiple representantions
type Token map[string]interface{}
type Identity struct {
Connection string `json:"connection,omitempt... |
package message_processor
import (
"context"
bot "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/mrdniwe/clc.wtf/internal/interfaces"
"github.com/mrdniwe/pasatyje/pkg/intf/tg"
)
type service struct {
linkSvc interfaces.LinkService
wl interfaces.WhitelistChecker
}
func (s *service) Process(c... |
package liferay
import internal "github.com/mdelapenya/lpn/internal"
// Commerce implementation for Liferay nightly images with Commerce
type Commerce struct {
Tag string
}
// GetContainerName returns the name of the container generated by this type of image
func (c Commerce) GetContainerName() string {
return int... |
package main
import (
"log"
"net"
"sort"
"sync"
"time"
)
type result struct {
addr string
min, max, total time.Duration
succ, fail int
}
func (r *result) ave() time.Duration {
return r.total / time.Duration(r.succ)
}
type byQualityDesc []result
func (p byQualityDesc) Len() int {
return le... |
package epaxos
import (
"github.com/cockroachdb/cockroach/pkg/util/interval"
"github.com/google/btree"
pb "github.com/nvanbenschoten/epaxos/epaxos/epaxospb"
)
func (p *epaxos) maxInstance(r pb.ReplicaID) *instance {
if maxInstItem := p.commands[r].Max(); maxInstItem != nil {
return maxInstItem.(*instance)
}
... |
package main
import (
"fmt"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/gonitor/gonitor/config"
)
// CORSMiddleware configures the CORS middleware.
func CORSMiddleware() gin.HandlerFunc {
return func(context *gin.Context) {
context.Writer.Header().Set("Access-Control-Allow-Origin", ... |
package gate
import (
"strconv"
"strings"
// third pkgs
log "github.com/cihub/seelog"
yaml "gopkg.in/yaml.v2"
// company pkgs
)
// ------------------------------------------------------
// Database model -- Begin
type Ring struct {
Id uint16
Name string
}
type App struct {
Id uint16
Name string
}
type I... |
// Copyright 2019 The Berglas 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 agre... |
package main
import (
"fmt"
"designPattern/AAY_factory_builder/c_builder_superman/superman"
)
func main() {
adultSuperMan := superman.GetAdultSuperMan()
fmt.Println(adultSuperMan.SpecialTalent)
}
|
package wfs
import "os"
func Exists(p string) bool {
if _, err := os.Stat(p); err != nil {
return false
}
return true
}
func IsDir(p string) bool {
if s, err := os.Stat(p); err != nil {
return false
} else {
return s.Mode()&os.ModeDir > 0
}
}
|
package atgo
import (
"context"
"fmt"
"github.com/hashicorp/errwrap"
pay "github.com/wondenge/at-go/payments"
"go.uber.org/zap"
)
// Collect money into your Payment Wallet by initiating transactions that deduct
// money from a customers Debit or Credit Card.
// These APIs are currently only available in Nigeria ... |
package runtime
import (
"fmt"
E "github.com/ionous/sashimi/event"
"github.com/ionous/sashimi/meta"
"github.com/ionous/sashimi/runtime/api"
"github.com/ionous/sashimi/runtime/internal"
"log"
"math/rand"
"strings"
)
type RuntimeConfig struct {
core internal.RuntimeCore
}
func NewConfig() *RuntimeConfig {
re... |
package email
import (
"regexp"
)
func IsValid(email string) bool{
re := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
return re.MatchString(email)
} |
package msg
import (
"github.com/golang/protobuf/proto"
"github.com/wudiliujie/common/network"
"github.com/wudiliujie/common/network/protobuf"
)
var Processor = protobuf.NewProcessor()
func init() {
Processor.Register(PCK_C2SLogin_ID, func() network.IMessage { return new(C2SLogin) })
Processor.Register(PCK_S2CL... |
package leetcode
import (
"reflect"
"testing"
)
func TestPascalsTriangle(t *testing.T) {
tests := []struct {
input int
want [][]int
}{
{0, nil},
{1, [][]int{[]int{1}}},
{5, [][]int{[]int{1}, []int{1, 1}, []int{1, 2, 1}, []int{1, 3, 3, 1}, []int{1, 4, 6, 4, 1}}},
}
for _, tt := range tests {
if !re... |
// +build storage_sqlite storage_all !sqlite_fs,!storage_boltdb,!storage_badger,!storage_pgx
package sqlite
import (
"fmt"
"path"
"strings"
pub "github.com/go-ap/activitypub"
ap "github.com/go-ap/fedbox/activitypub"
"github.com/go-ap/handlers"
"github.com/go-ap/storage"
)
func isCollection(col string) bool {... |
// Copyright (c) 2016-2017 Tigera, 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 ... |
package repository
import (
"errors"
"github.com/Mangaba-Labs/ape-finance-api/pkg/domain/user"
"gorm.io/gorm"
)
// Repository concrete type
type Repository struct {
DB *gorm.DB // this can be any gorm instance
}
func (r Repository) FindAll() (users *gorm.DB, err error) {
users = r.DB.Find(&users)
err = users.... |
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
"github.com/jackc/pgx/v4"
)
func main() {
s := `
schema {
query: Query
}
type Query {
GetThread(): Thread
}
type Thread {
id: String
author: St... |
package br
import (
"regexp"
"strconv"
"strings"
"time"
"github.com/olebedev/when/rules"
)
func ExactMonthDate(s rules.Strategy) rules.Rule {
overwrite := s == rules.Override
return &rules.F{
RegExp: regexp.MustCompile("(?i)" +
"(?:\\W|^)" +
"(?:(?:(\\d{1,2})|(" + ORDINAL_WORDS_PATTERN[3:] + // skip ... |
package pipa
import (
"io"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("RetryPolicy", func() {
It("should retry", func() {
var n int
err := (RetryPolicy{}).Perform(func() error {
n++
return io.EOF
})
Expect(err).To(Equal(io.EOF))
Expect(n).To(Equal(1))
er... |
package Reverse_Linked_List
type ListNode struct {
Val int
Next *ListNode
}
//the first and better answer
func reverseList(head *ListNode) *ListNode {
return reverseListRecursive(head)
}
func reverseListRecursive(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
return head
}
node := reverse... |
package Integer
type Integer int
func (a Integer) Less(b Integer) bool {
return a < b
}
// func (a *Integer) Add(b Integer) Integer {
// ret := (*a + b)
// return ret
// }
func (a *Integer) Add(b Integer) {
*a += b
}
|
// https://programmers.co.kr/learn/courses/30/lessons/42860
package main
func p42860(name string) int {
m := make([]int, len(name))
for i, v := range name {
m[i] = int(v - 65)
if m[i] > 13 {
m[i] = 26 - m[i]
}
}
var ans, max, length, idx int
for i, v := range m {
if v == 0 {
length++
if max < ... |
package main
import (
"flag"
"github.com/codeskyblue/go-sh"
)
func conversionSearchVersion(version string) string {
switch version {
case "2.2":
return "2.2_r1.1"
case "2.3":
return "2.3_r1.10"
case "2.3.7":
return "2.3.7_r1.0"
case "4.0.1":
return "4.0.1_r1.0"
case "4.0.3":
return "4.0.3_r1.0"
ca... |
/*
Copyright 2020 The KubeSphere 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 main
import "fmt"
func main() {
myGreeting := map[string]string{
"Bob": "Good Morning",
"Vladamir": "Dobroe Ootro",
}
fmt.Println(myGreeting)
}
|
package test
import (
"io/ioutil"
"os"
"testing"
"github.com/CharellKing/z_gateway/idl"
"github.com/sirupsen/logrus"
)
func TestJson2Struct(t *testing.T) {
goPath := os.Getenv("GOPATH")
content, err := ioutil.ReadFile(goPath + "/src/github.com/CharellKing/z_gateway/idl/test/samples/module.json")
if err != n... |
package pkg
import (
"log"
"path/filepath"
"testing"
)
func TestSalting(t *testing.T) {
hash := generateKey("This is a bad passphrase")
log.Printf("Hashed passphrase : length %d, %x\n", len(hash), hash)
hash = generateKey("This is a bad passphrase")
log.Printf("Hashed passphrase : length %d, %x\n", len(hash), ... |
package server
import (
"bytes"
"context"
"github.com/sourcegraph/sourcegraph/cmd/frontend/db"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/gitserver"
)
func getTipCommit(repositoryID int) (string, error) {
repo, err := db.Repos.Get(context.Background(), api.Re... |
// 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, ... |
//go:build !android && !e2e_testing
// +build !android,!e2e_testing
package udp
import (
"encoding/binary"
"fmt"
"net"
"syscall"
"unsafe"
"github.com/rcrowley/go-metrics"
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/firewall"
"github.com/slackhq/nebula/header"
... |
package vmapis
import (
"github.com/gin-gonic/gin"
"goblog/vmcommon"
)
func Getvmlist(c *gin.Context) {
vmlist := vmcommon.GetVmList()
res := make(map[string]interface{})
res["res"] = vmlist
c.JSON(200, res)
}
func Createvm(c *gin.Context) {
create, err := vmcommon.Create("3ee18210-3761-4fdc-9141-f1... |
// This file was generated by counterfeiter
package fake_container_id_provider
import (
"sync"
"github.com/cloudfoundry-incubator/garden-shed/layercake"
"github.com/cloudfoundry-incubator/garden-shed/repository_fetcher"
)
type FakeContainerIDProvider struct {
ProvideIDStub func(path string) layercake.ID
... |
// 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 meta
import (
"context"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: LocalFeatures,
Desc: "Example to acce... |
package main
import "fmt"
var n int = 0
func Multiply(a, b int, reply *int) {
*reply = a * b
}
func main() {
reply := &n
Multiply(10, 5, reply)
fmt.Println("Multiply: ", *reply)
fmt.Printf("Value of n is %d", n)
}
|
package utils
import (
"net/http"
"github.com/stretchr/testify/mock"
)
// HTTPClient : used to define how a http client implementation should behave
type HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}
// HTTPClientDo : type to implement a Do function to the http client
type HTTPClientDo func(... |
package organize
import (
"errors"
"github.com/json-iterator/go"
"math/rand"
)
type Dynamic int
const (
CREATOR Dynamic = iota + 1
CREATOR_LEADER
CREATOR_SUPERIOR_LEADER
CREATOR_DEP
CREATOR_ROLE
CALLER
CALLER_LEADER
CALLER_SUPERIOR_LEADER
CALLER_DEP
CALLER_ROLE
)
func (static Dynamic) String() string {... |
package plugin
import (
"github.com/container-storage-interface/spec/lib/go/csi"
)
// Service Define CSI Interface
type Service interface {
csi.IdentityServer
csi.ControllerServer
csi.NodeServer
}
|
package font
// type (
// // PixelFontFace -
// PixelFontFace struct {
// tex *gfx.Texture
// PixelFontSettings
// }
// )
// // Glyph -
// func (o *PixelFontFace) Glyph(dot fixed.Point26_6, r rune) (bounds geom.Rect2i, mask *gfx.Texture, bearing geom.Point2i, advance int, ok bool) {
// ok = true
// if r < o.... |
package leetcode
import "testing"
func TestLeastInterval(t *testing.T) {
type args struct {
tasks []byte
n int
}
tests := []struct {
name string
args args
want int
}{
{
"With some input",
args {
tasks: []byte{'A','A','A','A','A','A', 'B', 'C', 'D','E','F','G'},
n: 2,
},
... |
// Package sort provides the needed in order to build sorting requests to the database.
package sorting
|
package nagiosplugin
// Nagios plugin exit status.
type Status uint
// The usual mapping from 0-3.
const (
OK Status = iota
WARNING
CRITICAL
UNKNOWN
)
// Returns string representation of a Status. Panics if given an invalid
// status (this will be recovered in check.Finish if it has been deferred).
func (s Statu... |
package main
import "fmt"
func main() {
// *******************************************
// range works on a variety of data structures
// *******************************************
// on arrays / slices
array := [5]int{1, 2, 3, 4, 5}
for key, val := range array {
fmt.Println("key: ", key, " value: ", val)
}... |
package server
import (
"context"
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/rancher/dynamiclistener"
"github.com/rancher/dynamiclistener/server"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"... |
package bouncing
import (
"math"
)
func BouncingBall(h, bounce, window float64) int {
if h < 0 || bounce <= 0 || bounce >= 1 || window >= h || window <= 0 {
return -1
} else {
return int(math.Floor(math.Log(window/h)/math.Log(bounce))*2 + 1)
}
}
func BouncingBall_2(h, bounce, window float64) int {
if h < 0 ... |
package server
import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"go-elastic-hotels/services"
"net/http"
)
const (
ConnectionError = "Could not establish connection with Elastic Server"
searchName = "name"
ESSearchError = "Elastic server could not respond"
jsonMarshalError = "Could not marsha... |
package openrtb_ext
type ImpExtGlobalsun struct {
PlacementID string `json:"placementId"`
}
|
package task
import (
"fmt"
"reflect"
"github.com/pivotal-cf/on-demand-services-sdk/bosh"
"gopkg.in/yaml.v2"
)
func ManifestsAreTheSame(generateManifest, oldManifest []byte) (bool, error) {
regeneratedManifest, err := marshalBoshManifest(generateManifest)
if err != nil {
return false, err
}
ignoreUpdateBlo... |
package main
import (
"encoding/hex"
//"fmt"
"github.com/ontio/ontology/common"
)
type Event interface {
GetEventName() string
}
type CreateOrderEvent []interface{}
func (this CreateOrderEvent) GetEventName() string {
bytes, _ := hex.DecodeString(this[0].(string))
return string(bytes)
}
func (this CreateOrde... |
package requests
import (
"fmt"
"net/url"
"strings"
"github.com/atomicjolt/canvasapi"
)
// ExportGroupsInAndUsersInCategory Returns a csv file of users in format ready to import.
// https://canvas.instructure.com/doc/api/group_categories.html
//
// Path Parameters:
// # Path.GroupCategoryID (Required) ID
//
type... |
package controllers
import (
"github.com/astaxie/beego/orm"
"myproject/models"
"fmt"
)
// TSql is
func (c *ModelController) TSql() {
o := orm.NewOrm()
// var maps [] orm.Params
// num, err := o.Raw("select * from up").Values(&maps)
// var up models.Up
// err := o.Raw("select * from Up where id=6").QueryRow(&u... |
package main
import "fmt"
func main() {
//原地删除
/**
给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。
示例 1:
给定 nums = [3,2,2,3], val = 3,
函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。
你不需要考虑数组中超出新长度后面的元素。
给定 nums = [0,1,2,2,3,0,4,2],... |
package global
import (
"context"
"strconv"
"github.com/go-redis/redis/v8"
"shared/utility/errors"
"shared/utility/global"
"shared/utility/key"
)
const (
// field
FieldGuildID = "guild_id"
FieldGuildName = "guild_name"
)
type Guild struct {
*GuildID
*GuildName
*GuildUser
*GuildSet
}
func NewGuild(c... |
package mta
// MTA mta schema, the schema will contain the latest mta schema version
// and all the previous version will be as subset of the latest
// Todo - Add the missing properties to support the latest 3.2 version
type MTA struct {
// indicates MTA schema version, using semver.
SchemaVersion *string `yaml:"_sc... |
package postgresql_test
import (
"context"
"log"
"os"
"testing"
"github.com/adamluzsi/testcase"
"github.com/adamluzsi/testcase/assert"
"github.com/adamluzsi/testcase/random"
"github.com/adamluzsi/frameless/adapters/postgresql"
"github.com/adamluzsi/frameless/ports/guard/guardcontracts"
"github.com/adamluzs... |
package ch2
//在go源码中嵌入c代码,方式是放在包声明之后的注释中,并导入C这个包
//这个包实际是一个虚拟的包,只是为了告诉go build命令在编译这个go文件之前使用cgo对它进行预处理
//这种方式适用于调用少量的简单的C代码
//#include <stdio.h>
//void callC() {
// printf("Calling C code!\n");
//}
import "C"
import "fmt"
func callEmbedC() {
fmt.Println("A Go statement!")
C.callC()
fmt.Println("Another Go statem... |
package producer
import (
"gitlab.mytaxi.lk/pickme/k-stream/consumer"
"testing"
)
func TestMockProducer_Produce(t *testing.T) {
producer := NewMockProducer(t)
msg := &consumer.Record{
Key: []byte(string(`100`)),
Value: []byte(string(`100`)),
Partition: 1,
}
p, _, err := producer.Produce(msg)
... |
package jfroghelm
import (
"encoding/json"
"fmt"
"github.com/codefresh-io/nomios/pkg/hermes"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"net/http"
"time"
)
// JFrog struct
type JFrogHelm struct {
hermesSvc hermes.Service
}
type webhookPayload struct {
Artifactory struct {
Webhook struct {... |
// Copyright 2019 Yunion
//
// 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 writi... |
package main
import (
"log"
"net/http"
"shopping-cart/pkg/database"
"shopping-cart/pkg/routes"
"github.com/gorilla/mux"
)
func main() {
database.Connect()
router := mux.NewRouter()
router = routes.SetRoutes(router)
log.Fatal(http.ListenAndServe(":8008", router))
}
|
package floats
import (
"github.com/shawnsmithdev/zermelo/v2"
"unsafe"
)
// unsafeFlipSortFlip converts float slices to unsigned, flips some bits to allow sorting, sorts and unflips.
// F and U must be the same bit size, and len(buf) must be >= len(x)
// This will not work if NaNs are present in x. Remove them firs... |
// Copyright 2018 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package filecheck helps tests check permissions and ownership of on-disk files.
package filecheck
import (
"context"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
... |
package main
import "testing"
var Pool *ClientPool
func TestMain(m *testing.M) {
Pool = NewClientPool("127.0.0.1:9080")
// defer Pool.Close()
m.Run()
}
|
package database
import (
"fmt"
"strings"
)
// NewSQLInjectionError
func NewSQLInjectionError(s string, args ...string) error {
return &SqlInjectionError{fmt.Sprintf(s, args)}
}
// SqlInjectionError
type SqlInjectionError struct {
s string
}
func (e *SqlInjectionError) Error() string {
return e.s
}
func valid... |
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
)
func main() {
start := time.Now()
fmt.Printf("Result is %v \n", run())
log.Printf("Code took %s", time.Since(start))
}
func run() int {
f, err := os.Open("input.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()
sc... |
package main
import (
"encoding/json"
"fmt"
"strconv"
"github.com/aasisodiya/aws/s3"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
// HandleRequest Method (Using Headers)
func HandleRequest(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
if requ... |
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
jira "github.com/andygrunwald/go-jira"
pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/ma... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.