text stringlengths 11 4.05M |
|---|
package repoimpl
import (
"context"
"sync"
"williamfeng323/mooncake-duty/src/infrastructure/db"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
//ProjectRepo is the implementation of Project repository
type ProjectRepo struct {
collection *mongo.Collection
}
func init() {
db... |
package routing
import "sync"
type PrefixTable struct {
V map[string]*TableEntry
Mux sync.RWMutex
}
type TableEntry struct {
SequenceNumber uint32
NextHop string
}
// returns the next hop for the given destination name
// if the given destination name is does not exists, empty string is returned
func (table *Pr... |
/**
*@Author: haoxiongxiao
*@Date: 2019/3/28
*@Description: CREATE GO FILE controllers
*/
package controllers
import (
"bysj/models"
"bysj/services"
"github.com/kataras/iris"
)
type FeedBackController struct {
Ctx iris.Context
Service *services.FeedBackService
Common
}
func NewFeedBackController() *FeedBa... |
package board
import (
"fmt"
"testing"
)
func TestBoardPlace(t *testing.T) {
var b Board
err := b.Place(0, 0, 1)
if err != nil {
t.Fail()
}
err = b.Place(0, 1, 1)
if err != nil {
t.Fail()
}
// now placing where other player already is
err = b.Place(0, 0, 2)
if err == nil {
t.Fail()
}
}
func Tes... |
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/TeamChii/hello-lambda/hello"
"github.com/aws/aws-lambda-go/lambda"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
func init() {
runtime.GOMAXPROCS(1)
}
func main() {
var (
logger, _ = zap.NewProduction()... |
// Copyright 2014 Marc-Antoine Ruel. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package main
import (
"log"
"github.com/maruel/subcommands"
)
// Common flags.
type CommonFlags struct {
subcommands.CommandRunBase
Ver... |
package chapter3
// 課題1
// 以下のstructにgetterとsetterを実装してください。
// Getterの関数名ID, Name
// Setterの関数名SetID, SetName
type Kadai1 struct {
id int
name string
}
func (a Kadai1) ID() int {
return a.id
}
func (a *Kadai1) SetID(v int) {
a.id = v
}
func (a Kadai1) Name() string {
return a.name
}
func (a *Kadai1) SetNam... |
package twch
type Games struct {
client *Client
}
type Game struct {
Name *string `json:"name" `
Box *Asset `json:"box"`
Logo *Asset `json:"logo"`
GiantbombId *int `json:"giantbomb_id"`
Popularity *int `json:"popularity,omitempty"`
Viewers *int
Channels *int
}
type gameR... |
/*
* EVE Swagger Interface
*
* An OpenAPI for EVE Online
*
* OpenAPI spec version: 0.4.1.dev1
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
package swagger
// level object
type GetInsurancePricesLevel struct {
// cost number
Cost float32 `json:"cost,omitempty"`
// Localized in... |
package ch1
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
// DupUtil 模仿uniq的命令行工具,可以支持多个文件处理
func DupUtil(out io.Writer) {
var (
args []string
filePaths []string
)
for _, arg := range os.Args[1:] {
if strings.HasPrefix(arg, "-") {
args = append(args, arg)
}
filePaths = append(filePaths, arg)
... |
package main
import (
"fmt"
"bufio"
"os"
)
// Application enty point
func main() {
fmt.Printf("Welcome to the ASCII cipher!\n")
// Setup to accept user input as parameters from terminal
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Print("Encrypt/Decry... |
package Controllers
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/james-vaughn/PersonalWebsite/Models"
"github.com/james-vaughn/PersonalWebsite/Services"
)
type SteganographyController struct {
PagesService *Services.PagesService
pages []Models.Page
}
const SteganographyControllerName = "s... |
package main
import (
"bytes"
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"io/ioutil"
"log"
"net/http"
)
const url = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/party"
type Dates struct {
Value string
Kpp string
Ogrn string
Name string
}
func main() {
r := mux.NewRouter()
r.Ha... |
package auth
import (
"encoding/json"
log "github.com/z26100/log-go"
"io/ioutil"
"net/http"
)
type PublicKeyProvider interface {
Get() ([]byte, error)
}
type FilePublicKeyProvider struct {
filename string
publicKey []byte
}
type WebsitePublicKeyProvider struct {
url string
publicKey []byte
adapter ... |
/**
* Fileserver
* Programmieren II
*
* 8376497, Florian Braun
* 2581381, Lena Hoinkis
* 9043064, Marco Fuso
*/
package Templates
import (
"net/http"
"Utils"
"io"
"strconv"
"os"
"UserManager"
"Flags"
"SessionManager"
"github.com/pkg/errors"
"log"
"path/filepath"
"mime/multipart"
"io/ioutil"
... |
package test
import (
"MainApplication/internal/Letter/LetterModel"
"MainApplication/internal/Letter/LetterRepository"
"MainApplication/internal/Letter/LetterUseCase"
mock "MainApplication/test/mock_LetterRepository"
"github.com/golang/mock/gomock"
"testing"
)
func TestSaveLetter(t *testing.T) {
ctrl := gomock... |
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
package main
... |
package main
import (
"bytes"
"code.google.com/p/go.net/websocket"
"encoding/json"
"fmt"
"gameserver/module"
"loger"
"loginserver/msg"
"net/http"
"serverconfig"
"time"
)
func Test() {
fmt.Println("Hello")
}
type GameServer struct {
serverID int //! 游戏服务器ID
serverLimit ... |
package list_test
import (
"fmt"
"testing"
"github.com/ardanlabs/gotraining/topics/go/algorithms/data/list"
)
const succeed = "\u2713"
const failed = "\u2717"
// TestAdd validates the Add functionality.
func TestAdd(t *testing.T) {
t.Log("Given the need to test Add functionality.")
{
const nodes = 5
t.Logf... |
package pprof
import (
"fmt"
"io"
"sync"
"github.com/google/pprof/driver"
"github.com/kaz/pprotein/internal/collect"
"github.com/labstack/echo/v4"
)
type (
processor struct {
mu *sync.Mutex
route *echo.Group
}
)
func (p *processor) Cacheable() bool {
return false
}
func (p *processor) Process(snaps... |
package main
import "fmt"
/* By default channels are unbuffered, meaning that they
will only accept sends(chan<-) if there's a corresponding
receive (<-chan) ready to receive the sent value.
Buffered channels accept a liminted number of valued
without a corresponding receiver for those values */
func main(){
/*Here... |
package debugopencensus
import "go.opencensus.io/plugin/ocgrpc"
func init() {
var _ ocgrpc.ClientHandler
}
|
/*
*
* collection_name.go
* names
*
* Created by lintao on 2020/8/8 4:20 下午
* Copyright © 2020-2020 LINTAO. All rights reserved.
*
*/
package names
import (
"reflect"
"sync"
)
// CollectionName collection name driver to define customerize collection name
type CollectionName interface {
CollectionName() st... |
package tools
import (
"testing"
"github.com/graphql-go/graphql"
)
func TestMissingType(t *testing.T) {
typeDefs := `
type Foo {
name: String!
meta: JSON
}
input Cyclic {
name: String
cyclic: Cyclic
}
type Query {
foos: [Foo]
}`
// create some data
foos := []map[string]interface{}{
map[string]interfac... |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package azurestack
import (
"context"
"fmt"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-03-30/compute"
azcompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
)
// Vir... |
package main
import (
"flag"
"os"
"./models"
"./process"
_ "net/http/pprof"
)
// RunTime=dev go run app.go -conf "./conf/conf.toml"
var confPath = flag.String("conf", "./conf/conf.toml", "The conf path.")
func main() {
models.RunTime = os.Getenv("RunTime")
flag.Parse()
// init
process... |
package main
import "fmt"
func main() {
x := 42 //Declare and Initialize the variable x
fmt.Println("Initial value of x :: ", x)
x = 100 //Change the value of the already declared variable x
fmt.Println("New value of x :: ", x)
y := 10 + x //Initial value can also be given as an expression
fmt.Println("Value of... |
// Package types contains types that are used by werifyd and its worker pools. It doesn't try to be an elegant solution.
package types
import (
"fmt"
"net/rpc"
"sync"
"time"
wrpc "github.com/disq/werify/rpc"
)
// Host is the main struct for each host, satisfies the PoolData interface
type Host struct {
Endpoin... |
package events
type Bus struct {
topics map[string]*topic
}
func New() *Bus {
return &Bus{topics: make(map[string]*topic)}
}
func (d *Bus) On(event string, receiver interface{}) error {
// TODO: make thread safe
t, hasTopic := d.topics[event]
if !hasTopic {
t = &topic{}
d.topics[event] = t
}
sub, err := ... |
package hue
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func DiscoverAll() (dm []DiscoverModel, err error) {
resp, err := http.Get("https://discovery.meethue.com")
if err != nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
err = json.Unmarsh... |
package main
import (
"fmt"
"sync"
)
var lock = &sync.Mutex{}
type single struct {
}
var singleInstance *single
func getInstance() *single {
if singleInstance == nil {
lock.Lock()
defer lock.Unlock()
if singleInstance == nil {
fmt.Println("Creating single instnace now.")
singleInstance = &single{}
... |
package libp2pquic
import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"errors"
"net"
ic "github.com/libp2p/go-libp2p-core/crypto"
tpt "github.com/libp2p/go-libp2p-core/transport"
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
. "github.com/onsi/gi... |
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
"sort"
)
// IndividualEvents is the table of events show in the "Events" section of the
// individuals page.
type IndividualEvents struct {
document *gedcom.Document
individual *gedcom.IndividualNode
visibi... |
package main
import (
"fmt"
"strconv"
)
type MyStringer interface {
String() string
}
type Temp int
func (t Temp) String() string {
return strconv.Itoa(int(t)) + " ℃"
}
type Point struct {
x, y int
}
func (p *Point) String() string {
return fmt.Sprintf("(%d, %d)", p.x, p.y)
}
/**
* created: 2019/5/13 16:08... |
/*
Copyright 2020 Humio https://humio.com
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 datamodel
import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"strconv"
"time"
)
// Create a single sessions with mongo that'll be shared.
var session, serr = mgo.Dial("request.loltracker.com:27017")
type Retriever interface {
init()
}
/**
* CRUD operations on individual summoners.
*/
type Sum... |
package apptweak
import (
"encoding/json"
"net/http"
"strconv"
)
type AppKeywordsCompetitorsResponse struct {
CompetitorList []App `json:"content"`
MD MetaData `json:"metadata"`
}
type App struct {
ID int `json:"id"`
Title string `json:"title"`
Icon string `json:"icon"`
Genres... |
package dao
import (
"github.com/IsaiasMorochi/twitter-clone-backend/models"
"golang.org/x/crypto/bcrypt"
)
func Login(email string, password string) (models.Users, bool) {
user, foundUser, _ := CheckIfExistsUser(email)
if !foundUser {
return user, false
}
passwordBytes := []byte(password)
passwordBD := []... |
package main
import (
"fmt"
"reflect"
)
func main() {
var input = [][]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
isTrue(input)
res := int(5.0) % 2.0
fmt.Println(reflect.TypeOf(res), res)
IString = "Bobojon"
res := NewNumber("Qaroev")
fmt.Println(res, IString)
}
func isTrue(is [][]int) {
res := is[1:len(is)]
fmt... |
package main
import (
"fmt"
)
func main() {
favSport := "Running"
switch favSport {
case "Swimming":
fmt.Println("My Favourite sport is Swimming")
case "Fishing":
fmt.Println("My Favourite sport is Fishing")
case "Running":
fmt.Println("My Favourite sport is Running")
}
}
|
package service
import (
"sort"
"unicode"
)
func stringToRuneSlice(s string) []rune {
var r []rune
for _, runeValue := range s {
r = append(r, unicode.ToLower(runeValue))
}
return r
}
func sortStringByCharacter(s string) string {
r := stringToRuneSlice(s)
sort.Slice(r, func(i, j int) bool {
return r[i] <... |
package common
import (
"bytes"
"encoding/gob"
"log"
"net"
)
const (
// HANDSHAKE Initiates handshake
HANDSHAKE byte = 0x01
// HANDSHAKE_ACCEPTED accepts handshake
HANDSHAKE_ACCEPTED byte = 0x02
// CLIENT_CONFIGURATION sends client configuration
CLIENT_CONFIGURATION byte = 0x03
// SESSION_REQUEST requests ... |
// Written in 2014 by Petar Maymounkov.
//
// It helps future understanding of past knowledge to save
// this notice, so peers of other times and backgrounds can
// see history clearly.
package be_test
import (
"testing"
"github.com/hoijui/escher/pkg/be"
)
func TestSynapse(t *testing.T) {
x, y := be.NewSynapse()... |
package string_test
import (
"fmt"
stringutil "zshanjun/ec_startup/string"
"strings"
)
//是否存在某个字符或字串
func ExampleContains() {
fmt.Println(strings.Contains("team", "i"))
fmt.Println(strings.ContainsAny("failure", "u & i"))
fmt.Println(strings.ContainsAny("", ""))
// Output:
// false
// true
// false
}
//字串出... |
package main
import (
"time"
"encoding/gob"
"os"
"fmt"
"sync"
)
type dataProvider func() map[string]string
type setter func(string, string)
type Persister struct {
filePath string
lister dataProvider
sync.Mutex
}
func NewPersister(filePath string, lister dataProvider) *Persister {
return &Persister{fileP... |
//+build integration
package integration
import (
"context"
"fmt"
uuid "github.com/satori/go.uuid"
"os"
"strconv"
"sync/atomic"
"testing"
"time"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/nats-io/stan.go"
"github.com/stretchr/testify/suite"
"github.com/teploff/otus/scheduler/internal/app"
"github.com... |
package main
import (
"encoding/json"
"fmt"
)
type Monsters struct {
Name string `json:"name"` /*Ttag的重要意义在于让变量以你想要的格式返回*/
age int
skill string
}
func main() {
monsters1 := Monsters{"IronMan", 30, "robot"}
//序列化~~跟前端交互的,将monster变量序列化为json格式字符串
jsonStr, err := json.Marshal(monsters1)
if err != nil {
... |
package config
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/pomerium/pomerium/internal/urlutil"
)
func TestFromURLMatchesRequestURL(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
pattern string
input string
matches bool
}{
{"https://from.example.com", "h... |
package sdk
import (
"context"
"encoding/json"
"errors"
"sync"
"github.com/zaynjarvis/fyp/config/api"
"google.golang.org/grpc"
)
func GetConfig(cfg sync.Locker, name string, version uint32, cfgCenterAddr string) error {
conn, err := grpc.Dial(cfgCenterAddr, grpc.WithInsecure())
if err != nil {
return err
... |
package UserDelivery
import (
"context"
"fmt"
)
import proto "UserService/proto"
import "UserService/internal/UserUseCase"
type UserManager struct {
useCase UserUseCase.Interface
}
func New(uc UserUseCase.Interface) proto.UserServiceServer {
return UserManager{useCase: uc}
}
func (um UserManager) GetFoldersList... |
package main
import (
"fmt"
"net/http"
"strings"
"io/ioutil"
"image/jpeg"
"bytes"
"image"
"strconv"
"flag"
"os"
"sync"
"time"
)
type ObjStreetsLya struct {
STREET_NAME string
STREET_TYPE_CODE string
LONGITUDE string
LATITUDE string
STREET_LOCALITY_PID string
Data[] stri... |
package xdominion
import (
"fmt"
"testing"
)
func TestXTable_select(t *testing.T) {
base := &XBase{
DBType: DB_Postgres,
Username: "username",
Password: "password",
Database: "test",
Host: DB_Localhost,
SSL: false,
}
base.Logon()
tb := getTableDef(base)
tb.Synchronize()
buildData(tb)
... |
/*
create a program that will take user input and tell them their age in months, days, hours, and minutes
*/
package main
import "fmt"
func main() {
fmt.Println(age(18))
}
func age(year int) (months, days, hours, minutes int) {
months = 12 * year
days = months * 365
hours = days * 24
minutes = hours * 60
re... |
package storage
import (
"log"
"github.com/gocql/gocql"
)
type Storage struct {
db *gocql.Session
}
func SetupStorage() (*Storage, error) {
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "candy_shop_db"
cluster.Consistency = gocql.Quorum
session, err := cluster.CreateSession()
if err != nil {
... |
// Copyright Amazon.com Inc. or its affiliates. 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. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file ... |
package inner_server
type ModifyType int64
const (
ModifyTypePut ModifyType = 0
ModifyTypeDelete ModifyType = 1
)
type Put struct {
Key []byte
Value []byte
Cf string
}
type Delete struct {
Key []byte
Cf string
}
type Modify struct {
Type ModifyType
Data interface{}
}
|
package main
import (
"encoding/json"
"fmt"
"gaea/app/router"
"io/ioutil"
"net/http"
"os"
"syscall"
"testing"
"time"
"github.com/spf13/cast"
"github.com/tal-tech/hera/ginhttp"
logger "github.com/tal-tech/loggerX"
"github.com/tal-tech/xtools/confutil"
"github.com/tal-tech/xtools/flagutil"
)
func TestSer... |
package application
import (
"github.com/adampresley/webframework/logging"
"github.com/adampresley/webframework/middleware"
"github.com/adampresley/webframework/sanitizer"
"github.com/gobucket/gobucketlib"
"github.com/gobucket/gobucketserver/configuration"
"gopkg.in/mgo.v2"
)
/*
Application represents the prima... |
package tts
import (
"bytes"
"encoding/xml"
"log"
)
type convertText struct {
XMLName xml.Name `xml:"ConvertText"`
Account string `xml:"accountID"`
Password string `xml:"password"`
TTStext string `xml:"TTStext"`
TTSSpeaker string `xml:"TTSSpeaker"`
Volume string `xml:"volume"`
Speed... |
package generator
import (
"fmt"
"reflect"
"strings"
"text/template"
)
type structType struct {
Name string
Type string
Fields []structJSONField
}
type structJSONField struct {
Name string
Type string
ReturnType string
JSON string
Complex bool
Ptr bool
}
func writeStruct... |
package cmdutils
import (
"fmt"
"io"
"log"
)
func CheckError(err error) {
if err != nil {
log.Fatal(err)
}
}
func ClearConsole(writer io.Writer) error {
_, err := fmt.Fprint(writer, "\033[H\033[2J")
return err
}
|
/*
* @lc app=leetcode.cn id=312 lang=golang
*
* [312] 戳气球
*/
package main
import "fmt"
// @lc code=start
func max(a, b int) int {
if a > b {
return a
}
return b
}
func maxCoins(nums []int) int {
numsLen := len(nums)
rec := make([][]int, numsLen+2)
for i := 0; i < numsLen+2; i++ {
rec[i] = make([]int, nu... |
package api
func NewClient() {
}
|
package errors
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/go-pg/pg"
)
// Middleware provides a gin middleware to collect errors and deliver a response
func Middleware(c *gin.Context) {
// Wait for handler
c.Next()
// Only continue if response not yet written
if !c.Writer.Written() {
va... |
package main
type contactInfo struct {
email string
zipCode int
}
type person struct {
firstName string
lastName string
contact contactInfo
}
/*
create for interfaces sections
*/
type bot interface {
getGreeting() string
}
type englishBot struct{}
type spinishBot struct{}
func main() {
/* here is si... |
package main
import (
"fmt"
//"log"
//g "gosnmp"
//toml "toml"
//"io/ioutil"
"strings"
//"os"
//"time"
"os/exec"
)
func snmpget(user string,password string,ipadrr string) string {
out, err := exec.Command("snmpget", "-u", user, "-l", "au... |
package main
import (
"context"
"log"
"sync"
"time"
"github.com/brigadecore/brigade-foundations/os"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/brigadecore/brigade/v2/scheduler/internal/lib/queue"
)
type schedulerConfig struct {
healthcheckInterval time.Duration
addAndRemoveProjectsInterval... |
package cmd
import (
"net/http"
)
func LikeAdd(blockID string) error {
res, err := executeJsonCmd(http.MethodPost, "blocks/"+blockID+"/likes", params{}, nil)
if err != nil {
return err
}
output(res)
return nil
}
func LikeList(blockID string) error {
res, err := executeJsonCmd(http.MethodGet, "blocks/"+block... |
package rest
import (
"net/http"
"github.com/phiphi282/gorocket/api"
)
type imsResponse struct {
Success bool `json:"success"`
Channels []api.Channel `json:"ims"`
}
// Returns all direct messages that the user has joined.
//
// https://rocket.chat/docs/developer-guides/rest-api/im/list
func (c *Client... |
package gcloud
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
)
// GetServiceAccount reads file which contains google service account credentials and parse it
func GetServiceAccount() ServiceAccount {
var serviceaccount ServiceAccount
credentialPath := os.Getenv("GOOGLE_APPLICATION_CRE... |
package main
import (
"fmt"
. "leetcode"
)
func main() {
fmt.Println(isSubStructure(NewTreeNode(3, 4, 5, 1, 2), NewTreeNode(4, 1)))
fmt.Println(isSubStructure(NewTreeNode(4, 2, 3, 4, 5, 6, 7, 8, 9), NewTreeNode(4, 8, 9)))
//[3,4,5,1,2], B = [4,1]
}
func isSubStructure(A *TreeNode, B *TreeNode) bool {
if B == ... |
package main
import "math"
func trap(height []int) int {
if height == nil || len(height) < 3 {
return 0
}
max := 0
lmax := 0
rmax := 0
i := 0
j := len(height) - 1
for i < j {
lmax = Max(lmax, height[i])
rmax = Max(rmax, height[j])
if lmax < rmax {
max += lmax - height[i]
i++
} else {
max +=... |
package pgp
import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/packet"
)
var DefaultConfig = &packet.Config{
DefaultCipher: packet.CipherAES256,
}
// Symmetric provides convenience functions to create and parse
// symmetrically PGP and base64 encod... |
package model
import (
"github.com/TRON-US/soter-order-service/common/errorm"
"github.com/go-xorm/xorm"
)
var (
queryBtfsFileInfoByHash = `SELECT id, file_hash, unix_timestamp(expire_time), version FROM btfs_file WHERE file_hash = ?`
insertBtfsFileSql = `INSERT INTO btfs_file (file_hash, expire_tim... |
package aliyun
import (
"os"
"path"
)
// inject neccessary index.handler adaptor for aliyun function
func (m* Manager) createPython3Function(dir string) error {
home, err := os.UserHomeDir()
if err != nil {
return err
}
// TODO: config
err = os.Link(path.Join(home, ".jfManager", "ali", "python3", "jointfaas... |
package main
import "github.com/tano/chess-tournament/cmd"
func main() {
cmd.PrintGreeting()
cmd.InteractWithUser()
cmd.PrintFarewell()
}
|
package main
import (
"fmt"
"log"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/tidwall/buntdb"
"github.com/thinkofher/lalyta/pkg/api"
"github.com/thinkofher/lalyta/pkg/service/params"
"github.com/thinkofher/lalyta/pkg/storage"
)
func run() error {
bunt, err := bu... |
package main
import (
"github.com/GoPex/caretaker/engine"
"github.com/GoPex/caretaker/helpers"
)
func main() {
// Create a new Unleash application
application := engine.New()
// Parse the configuration
config, err := helpers.ParseConfiguration()
if err != nil {
panic("Not able to parse the configuration ! C... |
package plugins
import (
"errors"
"github.com/darkliquid/go-ircevent"
"github.com/darkliquid/leader1/config"
"github.com/darkliquid/leader1/state"
"github.com/darkliquid/leader1/utils"
"github.com/robertkrimen/otto"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"strings"
)
type PluginManager struct {
... |
package main
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
"runtime"
"strings"
)
func main() {
_, file, _, _ := runtime.Caller(0)
content, err := ioutil.ReadFile(filepath.Join(filepath.Dir(file), "./input.txt"))
if err != nil {
log.Fatalln("load input error:", err)
}
rawInput := strings.Split(string(c... |
package util
import "time"
type Datetime time.Time
func (d Datetime) String() string {
return time.Time(d).String()
}
|
package main
import (
"fmt"
"sort"
)
func main() {
a := []string{"eat", "tea", "tan", "ate", "nat", "bat"}
fmt.Println(groupAnagrams(a))
}
func groupAnagrams(strs []string) [][]string {
res := [][]string{}
m := map[string][]string{}
for i := 0; i < len(strs); i++ {
temp := sortString(strs[i])
m[temp] = ... |
// Copyright 2019 Google LLC
//
// 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in ... |
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
var db *sql.DB
func initdb() (err error) {
sqn := `root:123456@tcp(192.168.56.101:3306)/gotest`
db, err = sql.Open("mysql", sqn)
if err != nil {
return
}
err = db.Ping()
if err != nil {
return
}
return
}
//插入数据函数
func in... |
package main
import "fmt"
func main() {
nums := []int{2, 3, 5, 1}
fmt.Println(rob(nums))
}
func rob(nums []int) int {
n := len(nums)
if n == 0 {
return 0
}
if n == 1 {
return nums[0]
}
return max(robRange(nums, 0, n-2), robRange(nums, 1, n-1))
}
func robRange(nums []int, start, end int) int {
//n :=... |
package main
import (
"fmt"
"io"
"net"
)
func main() {
conn, err := net.Dial("tcp", "www.baidu.com:80")
if err != nil {
fmt.Println("baidu connect failed, err:", err)
}
defer conn.Close()
msg := "GET / Http/1.1\r\n"
msg += "HOST: www.baidu.com\r\n"
msg += "connection: clost\r\n"
msg += "\r\n\r\n"
_, e... |
package user
import (
"crypto/md5"
"encoding/hex"
"errors"
"time"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"golang.org/x/crypto/bcrypt"
)
const (
USER = "USER"
ADMIN = "ADMIN"
)
// User model
type User struct {
ID int `json:"id,omitempty"`
... |
package main
import (
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/satori/go.uuid"
"log"
"net/http"
"os"
)
type ThxData struct {
From string `json:"from"`
Content string `json:"content"`
To string `json:"to"`
}
type HonorData struct {
Name string `json:"name"`
Score strin... |
package input
import (
"context"
"fmt"
"io"
"testing"
"time"
)
// TODO: Add tests
// - closing reader twice
// - cancel context to exit
// - multiple readers
// - error on read
// - error on decode
func TestProcessor(t *testing.T) {
tt := []struct {
name string
tc TypeCode
bs ... |
package models
import (
"github.com/jinzhu/gorm"
)
type GenresResult struct {
Genre string
Quantity int
}
func FindAllGenres(db *gorm.DB) (*[]GenresResult, error) {
var err error
genres := []GenresResult{}
err = db.Table("books").Select("genre, count(genre) as quantity").Group("genre").Scan(&genres).Error
... |
// 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 quick_find
import (
"bufio"
"fmt"
"os"
"reflect"
"strconv"
"strings"
"testing"
)
func TestInit(t *testing.T) {
cases := []struct {
in int
want *Sites
}{
{1, &Sites{[]int{0}, 1}},
{10, &Sites{[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 10}},
}
for _, c := range cases {
got := Init(c.in)
if !... |
package matchserver
import (
"errors"
"math/rand"
"sync"
"time"
"github.com/ekotlikoff/gochess/internal/model"
)
const clientGameoverNotifGracePeriod = 1 * time.Second
type (
// Match is a struct representing a game between two players
Match struct {
black *Player
white *Player
Game ... |
package biz
import (
"fmt"
"go_test/golang/test2/src/lib"
//"lib"
)
func formatTwoNumber(a, b int) string {
print(fmt.Sprintf("%d-%d\n", a, b))
return fmt.Sprintf("%d-%d\n", a, b)
}
func GetRandomPair() string {
print(formatTwoNumber(lib.GetRandomNumber(), lib.GetRandomNumber()))
return formatTwoNumber(lib.Get... |
package server
import (
"github.com/gin-gonic/gin"
"github.com/nvm-academy/go-102-packages/repository"
)
// Server contains the properties necessary to construct
// a runnable web server
type Server struct {
engine *gin.Engine
ipRepo repository.InteractionPropertyRepository
}
// NewServer creates a pointer to a ... |
package main
import (
"log"
"time"
"github.com/gorilla/websocket"
)
type Client struct {
ws *websocket.Conn
output chan string
connected bool
err error
quit chan struct{}
done chan struct{}
// TODO: add some stats on the ws client?
// reconnects int
// created time.Time
// ... |
package gorm_zerolog
import (
"context"
"errors"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
gormlogger "gorm.io/gorm/logger"
"gorm.io/gorm/utils"
)
type logger struct {
SlowThreshold time.Duration
SourceField string
SkipErrRecordNotFound bool
Logger ... |
package api
import (
"io/ioutil"
"log"
"math/big"
"net"
"net/http"
"net/http/httptest"
"testing"
)
type mockOracle struct{}
func (r *mockOracle) LookupAddr(net.IP) ([]string, error) { return []string{"localhost"}, nil }
func (r *mockOracle) LookupCountry(net.IP) (string, error) { return "Elbonia", nil }
func... |
package test_go1
import (
"fmt"
a "github.com/a8uhnf/test-go2"
)
func HelloWorld() {
fmt.Println("Hello World from test-go1")
a.HelloWorldTestDep()
}
|
package t
import (
"os"
"testing"
)
func TestMain(m *testing.M) {
/// init
/// run
exitCode := m.Run()
/// clean up
os.Exit(exitCode)
}
func TestSimple(t *testing.T) {
got := 1
want := 2
if got != want {
t.Fatalf("want %v, but %v:", want, got)
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.