text stringlengths 11 4.05M |
|---|
package tools
import (
"fmt"
"net/http"
"runtime"
)
var (
//Max_Num = os.Getenv("MAX_NUM")
MaxWorker = runtime.NumCPU()
MaxQueue = 1000
)
type Serload struct {
pri string
}
type Job struct {
serload Serload
}
var JobQueue chan Job
type Worker struct {
WorkerPool chan chan Job
JobChannel chan Job
Quit ... |
package models_test
import (
"encoding/json"
"github.com/APTrust/exchange/models"
"github.com/stretchr/testify/assert"
"io/ioutil"
"path/filepath"
"testing"
"time"
)
func TestDeleteAttemptedAndSucceeded(t *testing.T) {
// TODO: Need a more reliable way to get path to test data file
filepath := filepath.Join(... |
package annotations_test
import (
"github.com/haproxytech/kubernetes-ingress/controller/annotations"
"github.com/haproxytech/kubernetes-ingress/controller/store"
)
func (suite *AnnotationSuite) TestGlobalCfgSnippetUpdate() {
tests := []struct {
input store.StringW
expected string
}{
{store.StringW{Value:... |
package hybrid
import (
"fmt"
"strings"
"time"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/retry"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/kumahq/kuma/pkg/config/cor... |
package main
import (
"fmt"
"math"
"math/big"
"reflect"
)
func main() {
fmt.Println(1, 2, 1000)
fmt.Println("Literal inteiro", reflect.TypeOf(32000))
// Apenas números positivos (conjunto dos Naturais)
var a uint8 = 5
var b uint16 = 20
var c uint32 = 500
var d uint64 = 35441125
var a2 byte = 8
fmt.Pri... |
package day1
import (
"testing"
"github.com/achakravarty/30-days-of-go/assert"
)
type testCase struct {
value1 interface{}
value2 interface{}
expected interface{}
}
var numbers = []testCase{
testCase{value1: 1, value2: 2, expected: 3}}
var doubles = []testCase{
testCase{value1: float32(1.0), value2: floa... |
package bootstrap
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/openshift/installer/pkg/types"
)
func TestMergedMirrorSets(t *testing.T) {
tests := []struct {
name string
input []types.ImageDigestSource
expected []types.ImageDigestSource
}{{
input: []types.ImageDigestSource... |
package app
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
"github.com/cloudrimmers/imt2681-assignment3/lib/database"
"github.com/cloudrimmers/imt2681-assignment3/lib/types"
)
// App ...
type App struct {
FixerioURI string
CollectionFixerName string
Mongo database.Mongo... |
package fileutil
import (
"os"
"time"
)
// FileSummary includes the intersection of the set of
// file attributes available from os.FileInfo and tar.Header.
type FileSummary struct {
RelPath string
AbsPath string
Mode os.FileMode
Size int64
ModTime time.Time
IsDir b... |
package main
import "fmt"
// 小孩结构体
type Boy struct {
No int // 编号
Next *Boy // 指向下一个小孩的指针
}
// 编写一个函数,构成单项环形链表
// num 表示小孩子的个数
// *boy 返回该环形链表的第一个小孩指针
func AddBoy(num int) *Boy {
first := &Boy{} // 空节点
curBoy := &Boy{} // 空节点
// 判断
if num < 1 {
fmt.Println("num的值不对")
return first
}
// 循环的构建这个环形的链表
... |
/*
Copyright 2019 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 dao
import (
"webapp/entities"
)
// DAO interface for Student
type StudentDAO interface {
FindAll() []entities.Student
Find(id int) *entities.Student
Exists(id int) bool
Delete(id int) bool
Create(student entities.Student) bool
Update(student entities.Student) bool
}
|
package mqtt
import (
"os/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
var _ = BeforeSuite(func() {
cmd := exec.Command("sh", "-c", "docker run --detach --rm --name mosquitto --publish 1883:1883 eclipse-mosquitto")
err := cmd.Run()
Ω(err).NotTo(HaveOccurred(... |
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
"strings"
)
type Question struct {
Subject string
Text string
}
func main() {
questions := []Question{
Question{
Subject: "name",
Text: "Please enter your first name...",
},
Question{
Subject: "address",
... |
package evs
import (
"github.com/apache/pulsar-client-go/pulsar"
pb "github.com/cybermaggedon/evs-golang-api/protos"
"github.com/golang/protobuf/proto"
)
// Wraps Pulsar communication and cyberprobe event encoding
type EventProducer struct {
*Producer
}
// Initialise the analyitc
func NewEventProducer(c HasOutpu... |
package sqlite
import (
"database/sql"
"time"
"github.com/Tanibox/tania-core/src/assets/domain"
"github.com/Tanibox/tania-core/src/assets/repository"
"github.com/Tanibox/tania-core/src/assets/storage"
)
type MaterialReadRepositorySqlite struct {
DB *sql.DB
}
func NewMaterialReadRepositorySqlite(db *sql.DB) re... |
package pg
import (
"context"
"database/sql"
"time"
"github.com/tnclong/go-que"
)
type job struct {
db *sql.DB
tx *sql.Tx
id int64
queue string
args []byte
runAt time.Time
retryCount int
lastErrMsg sql.NullString
lastErrStack sql.NullString
}
func (j *job) ID() int64 {
return j.id
}
func (... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//39. Combination Sum
//Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations i... |
package secret
import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"strings"
"gopkg.in/yaml.v2"
uuid "github.com/satori/go.uuid"
"golang.org/x/crypto/ssh/terminal"
"github.com/werf/logboek"
"github.com/werf/logboek/pkg/style"
"github.com/werf/werf/p... |
package main
import (
"bytes"
"encoding/json"
"flag"
"os/exec"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"text/template"
"github.com/gorilla/mux"
)
// config
var saveFile = "./sites.json"
var saveCaddyFile = "./Caddyfile"
// models
type Site struct {
Id int `json:"id"`
Title ... |
package internal
import (
"encoding/json"
"fmt"
"os"
)
type Config struct {
Tokens []authToken
}
func NewConfig() (config *Config) {
config = &Config{}
err := json.Unmarshal([]byte(os.Getenv("TOKENS")), &config.Tokens)
if err != nil {
panic(fmt.Sprintf("NewConfig, %v", err))
}
// We are associating images... |
package Solution
import (
"reflect"
"strconv"
"testing"
)
func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
nums []int
expect int
}{
{"TestCase", []int{3,3,3,3,5,5,5,2,2,7}, 2},
{"TestCase", []int{7,7,7,7,7,7}, 1},
{"TestCase", []int{1000,1000,3,7}, 1},
{"TestCase", []int... |
package pn532
import (
"bytes"
"errors"
"github.com/zyxar/berry/core"
)
var (
ErrPageOutOfRange = errors.New("page out of range")
ErrNoAckReceived = errors.New("no ack received")
ErrInvalidDataLen = errors.New("invalid length of data")
)
// Tries to read an entire 4-byte page at the specified address
// TAG ... |
package cmd
import (
"fmt"
"github.com/eibhleag/trictrac/core"
"github.com/spf13/cobra"
)
// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get [key]",
Short: "get the value at a key",
Run: func(cmd *cobra.Command, args []string) {
c := core.OpenCollection()
key := args[0]
value :... |
package fullrt
import (
"fmt"
"time"
kaddht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p-kad-dht/crawler"
"github.com/libp2p/go-libp2p-kad-dht/providers"
)
type config struct {
dhtOpts []kaddht.Option
crawlInterval time.Duration
waitFrac float64
bulkSendParallelism in... |
package cancelot
import (
"bytes"
"context"
"log"
"os/exec"
"strings"
"cloud.google.com/go/compute/metadata"
"golang.org/x/oauth2/google"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)
// getProject gets the project ID.
func getProject() (string, error) {
// Test if we're running on GCE.
if metadata.On... |
//+build !test
package main
import (
"fmt"
"gitlab.com/gitmate-micro/listen/provider"
"github.com/micro/go-log"
"github.com/micro/go-web"
)
func main() {
fmt.Print(`
___ __
/ (_)____/ /____ ____
/ / / ___/ __/ _ \/ __ \
/ / (__ ) /_/ __/ / / /
/_/_/____/\__/\___/_/ /_/ s... |
package main
import (
"fmt"
"os"
)
func main() {
baseDir := "/home/test/go/src/go-leanring/file/"
file, err := os.Open(baseDir + "astaxie.txt")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
buf := make([]byte, 1024)
for {
n, _ := file.Read(buf)
if n == 0 {
break
}
os.Stdout.Writ... |
package day8
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
//DayEightOne Day eight task one
func DayEightOne() {
input, err := ioutil.ReadFile("./8/input.txt")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
accumulator := 0
rowsAlreadyChecked := []int{}
row := 0
instrucions := strings.Split(s... |
package helper
import (
"crypto/rand"
"fmt"
"math/big"
"os"
"strings"
"testing"
lorem "github.com/drhodes/golorem"
log "github.com/sirupsen/logrus"
)
const (
MaxRand = 1000000
LoremMin = 50
LoremMax = 100
)
func Lipsum() string {
return lorem.Paragraph(LoremMin, LoremMax)
}
func SplitTrim(s string) []... |
package control
import (
"encoding/json"
"testing"
"github.com/square/p2/pkg/pc/fields"
rc_fields "github.com/square/p2/pkg/rc/fields"
"github.com/square/p2/pkg/store/consul/consultest"
"github.com/square/p2/pkg/store/consul/pcstore"
"github.com/square/p2/pkg/store/consul/pcstore/pcstoretest"
"github.com/squa... |
package bitcask
import (
"os"
)
type bufwriter struct {
f *os.File
used int
buf []byte
}
func newBufWriter(f *os.File, bufsz uint32) *bufwriter {
bw := &bufwriter{}
bw.f = f
bw.buf = make([]byte, bufsz, bufsz)
bw.used = 0
return bw
}
func (bw *bufwriter) Write(data []byte) (int, error) {
if len(data)+... |
// Implementação do comando echo. Versão 6.
// arataca89@gmail.com
// 20210412
package main
import (
"fmt"
"os"
)
func main() {
for i := 0; i < len(os.Args); i++ {
fmt.Println(i, ": ", os.Args[i])
}
}
/////////////////////////////////////////////////////////////////////
// Esta versão exib... |
package dao
type Manager interface {
Init(addr string,option...string)
CreateSession()(sd SessionData,err error)
GetSessionData(sessionId string)(sd SessionData,err error)
}
|
package workflow
import (
"context"
"fmt"
)
type State string
type WorkflowExecRequest struct {
WorkflowID string `json:"workflow_id"`
}
type WorkflowExecResponse struct{}
type WorkflowArguments map[string]TaskArguments
func (wm *WorkflowManager) Exec(ctx context.Context, w *Workflow, args WorkflowArguments) (... |
package category
import (
"github.com/evleria/quiz-cli/pkg/cmd/category/list"
"github.com/evleria/quiz-cli/pkg/cmdutils"
"github.com/spf13/cobra"
)
func NewCategoryCmd(factory *cmdutils.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "category",
Short: "shows information of categories",
}
cmd.AddCo... |
package main
func (this *Application) LogsAction(args []string) {
}
|
package main
import (
"context"
"os"
"testing"
"cloud.google.com/go/datastore"
)
func TestController_storeMessage(t *testing.T) {
projectID := os.Getenv("GCLOUD_DATASET_ID")
cli, err := datastore.NewClient(context.Background(), projectID)
if err != nil {
t.Error(err)
}
type fields struct {
store *datas... |
package cosmos
import "context"
type User struct {
client Client
db Database
userID string
}
type UserDefinition struct {
Resource
_persmissions string `json:"_persmissions,omitempty"`
}
type Users struct {
client Client
db Database
}
func (u User) Permission(id string) *Permission {
return newPerm... |
package yara
import (
) |
package main
import (
"fmt"
)
func main() {
var nums []int
nums = []int{0, 1, 2, 4, 5, 7}
fmt.Printf("%#v\n", summaryRanges(nums))
nums = []int{0, 2, 3, 4, 6, 8, 9}
fmt.Printf("%#v\n", summaryRanges(nums))
nums = []int{}
fmt.Printf("%#v\n", summaryRanges(nums))
nums = []int{-1}
fmt.Printf("%#v\n", summa... |
package export
import (
"github.com/Zenika/marcel/api/db/plugins"
)
func Plugins(outputFile string, pretty bool) error {
return export(func() (interface{}, error) {
return plugins.List()
}, outputFile, pretty)
}
|
package module
import (
"bytes"
"encoding/json"
"errors"
"github.com/zieckey/simgo"
"io/ioutil"
"log"
"net/http"
"sync"
)
var (
ErrConvert = errors.New("convert error")
mu sync.Mutex
)
//解析查询参数
type SearchRequestParams struct {
Days []interface{} `json:"days"`
Page_size int32 ... |
package admin
import (
"firstProject/app/http/result"
"fmt"
"math/rand"
"os"
"time"
"github.com/gin-gonic/gin"
)
func UploadImg(c *gin.Context) {
returnData := result.NewResult(c)
// 获取上传文件,返回的是multipart.FileHeader对象,代表一个文件,里面包含了文件名之类的详细信息
// upload是表单字段名字
file, _ := c.FormFile("upload")
// 打印上传的文件名
fmt.... |
package mwords // import "cpl.li/go/cryptor/internal/crypt/mwords"
|
package fifth
import (
"fmt"
"testing"
)
func TestIfElseThen(t *testing.T) {
i := NewInterpreter()
var tests = []struct {
input string
want string
}{
{"0 hello .s", "[1 2]"},
{"1 hello .s", "[2]"},
{"0 foo .s", "[1 2 2]"},
{"1 foo .s", "[2]"},
{"0 hoge .s", "[1 2]"},
{"1 hoge .s", "[3 4]"},
}
... |
package aclient
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"time"
"github.com/henglory/Demo_Golang_v0.0.1/spec"
)
type AClient struct {
url string
loggingFn func(info interface{}) error
client interface {
Do(req *http.Request) (*http.Response, error)
}
}
func New(url string, timeou... |
package utils
import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"reflect"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/core/types"
)
// DecodeTransactionInput : contractName, encodeData
func DecodeTransactionInput(contractName string, encodeData string) (b... |
package wallet
import (
"context"
"sync"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/Secured-Finance/dione/sigs"
_ "github.com/Secured-Finance/dione/sigs/ed25519" // enable ed25519 signatures
"github.com/Secured-Finance/dione/types"
"github.com/filecoin-project/go-address"
"github.com/sirupsen/logrus... |
// Copyright 2017 Vckai Author. 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 friend
import (
"errors"
"fmt"
)
// Friend holds the properties for tracking my relationships.
type Friend struct {
name string
age int
ageOffset int
liesAboutAge bool
}
// NewFriend initializes a returns a new friend
func NewFriend(name string, age int) *Friend {
return &Friend{
... |
// Variables
package main
import "fmt"
func main() {
var a string = "empezar"
fmt.Println("a = ", a)
var b, c, h int = 4, 5, 0
fmt.Println("b, c, h", b, c, h)
var i = 3
fmt.Println("i = ", i)
var d = true
fmt.Println("d = ", d)
var e int
fmt.Println("e = ", e)
var j bool
fmt.Println("j = ", j)
f:... |
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
)
type InForMation_All_b42661db struct {
Id int
Url string
Title string
Author string
Source string
Release_datetime string
Content string
Media_type ... |
package svcs
import (
"database/sql"
"errors"
"week02/dao"
"week02/dtos"
)
// GetStudentByID 根据id获取学生数据
func GetStudentByID(id int) (*dtos.Student, error) {
data, err := dao.QueryByID(id)
if errors.Is(err, sql.ErrNoRows) {
return &dtos.Student{ID: "111", Name: "check", Age: 28}, err
}
return data.(*dtos.Stu... |
// Copyright 2020 The Reed Developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
package miner
import (
"bytes"
"fmt"
bc "github.com/reed/blockchain"
"github.com/reed/blockchain/merkle"
"github.com/reed/consensus/pow"... |
// Memcache server, which uses YBC library as caching backend.
//
// Thanks to YBC, the server has the following features missing
// in the original memcached:
// * Cache content survives server restarts if it is backed by files.
// * Cache size may exceed available RAM size by multiple orders of magnitude.
// ... |
package iam
import (
"app-auth/db"
"app-auth/types"
"context"
"github.com/mongodb/mongo-go-driver/bson"
"log"
"strings"
)
type Scope struct {
Scopes []string `json:"scopes"`
App string `json:"app"`
scopes []types.Scopes
permissions []string
}
// toString() representation of the
func (scope Scope) String()... |
package chatbots
import (
"context"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func cmdStart(c ChatBot, message *tgbotapi.Message) (err error) {
settings, err := c.storage.GetSettings(context.Background())
if err != nil {
_, err = c.botClient.Send(tgbotapi.NewMessage(message.Chat.ID, "... |
package sign
import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"unicode"
"golang.org/x/crypto/openpgp"
"github.com/goreleaser/nfpm/v2"
)
// PGPSigner returns a PGP signer that creates a detached non-ASCII-armored
// signature and is compatible with rpmpack's signature API.
func PGPSigner(keyFile, passphrase ... |
package build
import (
"fmt"
"log"
"math/rand"
"net/url"
"os"
"path/filepath"
"runtime"
"sync"
"time"
)
// App the current app we want to build (never changes so we can make it static)
var App = &Target{}
func init() {
var err error
bind := randomLocalBind()
// We want to build on the first request
App... |
package router
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/cswank/quimby/internal/schema"
"github.com/cswank/quimby/internal/templates"
"github.com/go-chi/chi"
"github.com/gorilla/websocket"
)
// getAll shows all the gadgets
func (g *serve... |
package vx
/*
#cgo CFLAGS: -mavx -mfma -std=c11
#cgo LDFLAGS: -lm
#include <immintrin.h>
void vx_add(const size_t size, const float *x, const float *y, float *z) {
__m256 *vx = (__m256 *)x;
__m256 *vy = (__m256 *)y;
__m256 *vz = (__m256 *)z;
const size_t l = size / 8;
for (size_t i = 0; i < l; +... |
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"time"
)
func copyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer func() {
if e := out.Clos... |
// 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... |
package main
import (
"fmt"
//"ms/sun_old/base"
"ms/sun/shared/x"
"ms/sun/shared/base"
)
func main() {
//x.LogTableSqlReq
n:=0
next := func() int {
n++
return n
}
i := 0
work := func() {
for ; i < 1000000; i++ {
m := next()
p := x.HomeFano... |
/*
* @lc app=leetcode.cn id=74 lang=golang
*
* [74] 搜索二维矩阵
*/
package main
import "fmt"
// @lc code=start
func searchMatrix(matrix [][]int, target int) bool {
rows, cols := len(matrix), len(matrix[0])
for i := 0; i < rows; i++ {
for j := 0; j < cols; j++ {
low, high := 0, cols-1
if matrix[i][high] < tar... |
/*
- implementation of POP3 server according to rfc1939, rfc2449 in progress
*/
package popgun
import (
"bufio"
"fmt"
"io"
"log"
"net"
"strings"
"time"
)
const (
STATE_AUTHORIZATION = iota + 1
STATE_TRANSACTION
STATE_UPDATE
)
type Config struct {
ListenInterface string `json:"listen_interface"`
}
type A... |
package msg_queue
import (
"testing"
"github.com/nsqio/go-nsq"
"log"
log2 "git.zhuzi.me/zzjz/zhuzi-bootstrap/lib/log"
)
type Handler struct {
}
func (p *Handler) HandleMessage(message *nsq.Message) error {
log.Print(string(message.Body))
return nil
}
func TestPublish(t *testing.T) {
bs := []byte("bs")
err ... |
package chapter9
import (
"fmt"
"testing"
)
func inOrderTraversal(root *TreeNode) {
if root == nil {
return
} else {
inOrderTraversal(root.Left)
fmt.Println(root.Value)
inOrderTraversal(root.Right)
}
}
func TestReconstructBinaryTreePreInOrders(t *testing.T) {
in := []string{"F", "B", "A", "E", "H", "C"... |
package router
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/julienschmidt/httprouter"
"github.com/yosssi/orgs.io/app/models"
)
func TestNew(t *testing.T) {
config := &models.Config{
App: models.AppConfig{
Env: models.EnvDevelopment,
},
Server: models.ServerConfig{},
}
if rtr := New... |
package fshelper
import (
"crypto/rand"
"fmt"
"os"
"path"
"strconv"
"testing"
"github.com/mitro42/coback/catalog"
th "github.com/mitro42/testhelper"
"github.com/spf13/afero"
)
func TestNextUnusedFolder(t *testing.T) {
fs := afero.NewMemMapFs()
th.Equals(t, "1", NextUnusedFolder(fs))
th.Equals(t, "1", Ne... |
// Copyright 2013 http://gumuz.nl/. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package core
import (
// "fmt"
// "sync"
// "io"
// "net/http"
// "lixae/settings"
"lixae/treap"
)
type SyncWriteOperation struct {
operation string... |
package fstestutil // import "github.com/chubaoio/cbfs/fuse/fs/fstestutil"
|
package main
import "room"
var Env string = "development"
func main() {
chatServerAddress := room.InitConfig(Env).GetDialAddress("chat")
room.StartApiServer(chatServerAddress)
}
|
// Package json implements a JSON handler.
package json
import (
stdjson "encoding/json"
"io"
"sync"
log "github.com/go-playground/log/v8"
)
// Handler implementation.
type Handler struct {
m sync.Mutex
*stdjson.Encoder
}
// New handler.
func New(w io.Writer) *Handler {
return &Handler{
Encoder: stdjson.Ne... |
package actions
import (
"bytes"
"fmt"
"github.com/deis/helm/log"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/pop"
"github.com/kulado/wealthmind/kuladoapi/models"
)
// UploadHandler accepts a file upload
func UploadHandler(c buffalo.Context) error {
tx := c.Value("tx").(*pop.Connection)
request := c... |
package main
import (
"fmt"
"math"
)
// error is built in type in GO
func sqrt(num float64) (float64, error) {
if(num < 0) {
return 0.0, fmt.Errorf("sqrt of megative value (%f)", num)
}
return math.Sqrt(num), nil // nil is nothing, NULL or None
}
func main() {
s1, err := sqrt(2.0)
if err != nil {
fmt.Prin... |
package nectar
import (
"bytes"
"encoding/csv"
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/gholt/brimtext"
)
type CLIInstance struct {
Arg0 string
fatal func(cli *CLIInstance, err error)
fatalf ... |
package ants
import (
"runtime"
"time"
)
// 类似于Java的Runnable
type goWorker struct {
pool *Pool // 所属协程池
task chan func() // 实际运行的方法
recycleTime time.Time // expiry time
}
func (w *goWorker) run() {
// count + 1
w.pool.increaseRunning()
go func() {
// 回收资源
defer func() {
// count... |
package setting
import (
"io/ioutil"
yaml "gopkg.in/yaml.v2"
)
// ServerSettingType is a struct has properties in setting.yml
type ServerSettingType struct {
Port string `yaml:"Port"`
Debug bool `yaml:"Debug"`
TextdataDir string `yaml:"TextdataDir"`
DBHost string `yaml:"DBHost"`
DBPort ... |
// Copyright 2020 Thomas.Hoehenleitner [at] seerose.net
// Use of this source code is governed by a license that can be found in the LICENSE file.
package decoder
import (
"fmt"
"io"
"github.com/rokath/trice/internal/id"
)
// Bare is the Decoder instance for bare encoded trices.
type Bare struct {
Decoding
pay... |
package product
import (
"errors"
"gin-webapi/database"
"net/http"
"time"
product "gin-webapi/models/product"
"github.com/gin-gonic/gin"
"gopkg.in/mgo.v2/bson"
)
const ProductCollection = "product"
var (
errNotExist = errors.New("Products are not exist")
errInvalidID = errors.New("Invalid ID"... |
package main
import (
"fmt"
"testing"
)
func TestHandleWord(t *testing.T) {
sensitiveList := LoadSensitiveWords()
input := "hellboy wankycd dsviagra"
util := NewDFAUtil(sensitiveList)
newInput := util.HandleWord(input, '*')
expected := "****boy *****cd ds******"
if newInput != expected {
t.Errorf("Expected... |
package rtk
/*
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <rtklib.h>
void ppk_raw_to_rindex(gtime_t gpst, const char *bin,
const char *ofile, const char *nfile,
const char *gfile) {
rnxopt_t rnxopt = {0};
i... |
package keeper
import (
"context"
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/x/metadata/types"
)
type msgServer struct {
Keeper
}
// NewMsgServerImpl returns an implementation of the distribution MsgServer interface
// for the provided Keeper.
func NewMsgSer... |
/*
Resistors are electrical components that add resistance to a circuit. Resistance is measured in ohms. When resistors are connected in series, the total resistance is merely the sum of the individual resistances:
Rtotal = R1 + R2 + R3 + ...
When resistors are connected in parallel, the reciprocal of the total resi... |
package main
import (
"listing17/handlers"
"log"
"net/http"
)
func main() {
handlers.Routes()
log.Println("웹 서비스 실행 중: 포트: 4000")
http.ListenAndServe(":4000", nil)
}
|
package controller
import (
"context"
log "github.com/sirupsen/logrus"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/yaml"
"github.com/argoproj/argo/config"
"github.com/argoproj/argo/errors"
"github.com/argoproj/argo/persist/sqldb"
"github.com/argoproj/argo/util/instanceid"
"gith... |
package raw_client
import (
"context"
)
type GetAppStatusRequest struct {
App string `json:"app"`
}
type GetAppStatusResponse struct {
Enable bool `json:"enable"`
States map[string]GetAppStatusRequestState `json:"states"`
Actions []GetAppStatusRequestAction `json:"act... |
/*
Author:
Nicholas Siow | nick@siow.me
Alani Douglas | fresh@alani.style
Description:
Core webserver for http://alanick.us
*/
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"strings"
)
//------------------------------------------------------------
// CONFIGURATI... |
package main
func main() {
var ints = []int{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}
//准备两个游标
front := 1
end := 2
//记录front--end中间的砖块数量
var countQut = 0
//记录front--end中间间的总体积)
var countAll = 0
for {
if ints[end] >= ints[front] {
front = end //进行下一次循环
}
end++
}
}
//面试题 17.21. 直方图的水量
|
package main
import (
"bufio"
"fmt"
"log"
"os"
"github.com/guromityan/go-imgmd/lib"
"gopkg.in/alecthomas/kingpin.v2"
)
const version = "1.0.0"
var (
app = kingpin.New("imgmd", "Convert image to Markdown.")
target = app.Arg("target", "Target directory containing images.").Required().ExistingDir()
output = ... |
// +build ignore
package gorules
import "github.com/quasilyte/go-ruleguard/dsl/fluent"
func _(m fluent.Matcher) {
m.Match(`typeTest($x + $y)`).
Where(m["x"].Type.Is(`string`) && m["y"].Type.Is("string")).
Report(`concat`)
m.Match(`typeTest($x + $y)`).
Where(m["x"].Type.Is(`string`) && m["y"].Type.Is("string... |
package resolver
import (
"github.com/kivutar/chainz/service"
"github.com/op/go-logging"
"golang.org/x/net/context"
)
// Author resolves an author graphql query
func (r *Resolver) Author(ctx context.Context, args struct {
ID string
}) (*AuthorResolver, error) {
authorService := ctx.Value("services").(*service.Co... |
package diceprinter
import (
"fmt"
"github.com/appliedgocourses/dice"
"github.com/common-nighthawk/go-figure"
)
func Roll(sides int) {
fmt.Printf("Rolling a %d-sided die: %d\n", sides, dice.Roll(sides))
}
func Pretty(sides int) {
out := fmt.Sprintf("%d-sided roll: %d", sides, dice.Roll(sides))
f := figure.New... |
package vastflow
import (
"github.com/jack0liu/logs"
"reflect"
)
type AtlanticFlow interface {
Success(headwaters *Headwaters) error
Fail(headwaters *Headwaters) error
}
type AtlanticStream interface {
runSuccess(headwaters *Headwaters, flow AtlanticFlow)
runFail(headwaters *Headwaters, flow AtlanticFlow)
set... |
package main
import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"net"
"time"
"github.com/armon/go-socks5"
"github.com/foomo/htpasswd"
"go.uber.org/zap"
"golang.org/x/crypto/bcrypt"
"golang.org/x/net/context"
"gopkg.in/yaml.v2"
)
var logger *zap.Logger
func init() {
l, _ := zap.NewProduction()
logger = l
... |
package smfimage
import (
"image/color"
)
type Option func(*smfimage)
func Background(name string) Option {
return func(s *smfimage) {
switch name {
case "black":
s.backgroundColor = color.Black
case "white":
s.backgroundColor = color.White
case "transparent":
s.backgroundColor = color.Transparen... |
// Copyright 2019 Radiation Detection and Imaging (RDI), LLC
// Use of this source code is governed by the BSD 3-clause
// license that can be found in the LICENSE file.
package data
import (
"github.com/rditech/rdi-live/model/rdi/currentmode"
"github.com/proio-org/go-proio"
)
func CorrelateCmEvent(event *proio.E... |
package main
import (
"encoding/json"
"log"
"net/http"
"strings"
"sync"
"sync/atomic"
"github.com/marema31/namecheck/checker"
"github.com/marema31/namecheck/github"
"github.com/marema31/namecheck/twitter"
)
// Declare a real http.Client that we will override in tests
var web = http.DefaultClient
// Declare... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.