text stringlengths 11 4.05M |
|---|
// Copyright 2018 The gVisor 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 agree... |
package usecase
import (
"github.com/16francs/examin_go/domain/model"
"github.com/16francs/examin_go/domain/service"
)
// SampleUsecase - Usecase のサンプル
type SampleUsecase interface {
GetSample() (*model.Sample, error)
PostSample(name string) (*model.Sample, error)
}
type sampleUsecase struct {
service service.S... |
package shell
import (
"os"
"strings"
"github.com/redhat-openshift-ecosystem/openshift-preflight/cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
type scorecardCheck struct{}
func (p *scorecardCheck) validate(items []cli.OperatorSdkScorecardItem) (bool, error) {
foundTestFailed := false
if l... |
package ui
import (
"bytes"
)
// TitleUnderliner is the underline character for the title
var TitleUnderliner = "="
// Title is a UI component that renders a title
type Title struct {
text string
}
func NewTitle(title string) *Title {
return &Title{text: title}
}
// Format returns the formated string of the tit... |
package cli
import (
"fmt"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/dikaeinstein/godl/internal/app"
"github.com/dikaeinstein/godl/test"
)
func TestVersionCmd(t *testing.T) {
info := app.BuildInfo{
BuildTime: "2021-03-14 00:28",
GitHash: "02cb593",
GitTag: ... |
package main
import "fmt"
func main() {
i1 := 100
i2 := 077
i3 := 0x12343ef
fmt.Printf("i1:%d\n", i1)
fmt.Printf("i1:%b\n", i1) // 二进制表示
fmt.Printf("i1:%o\n", i1) // 八进制表示
fmt.Printf("i1:%x\n", i1) // 十六进制表示
fmt.Printf("i1:%T\n", i1) // 表示类型
fmt.Printf("i1:%v\n", i1) // 表示值
fmt.Println("===================... |
package worker
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"time"
// include for conditional pprof HTTP server
_ "net/http/pprof"
gocontext "context"
"contrib.go.opencensus.io/exporter/stackdriver"
... |
package main
// Leetcode 440. (hard)
func findKthNumber(n int, k int) int {
i := 1
prefix := 1
for i < k {
cnt := getCnt(prefix, n)
if i+cnt > k {
i++
prefix *= 10
} else if i+cnt <= k {
i += cnt
prefix++
}
}
return prefix
}
func getCnt(prefix, n int) int {
cur, next := prefix, prefix+1
cnt... |
package lc
// Time: O(n)
// Benchmark: 0ms 2mb | 100%
func maxRepeating(sequence string, word string) int {
size := len(word)
var matches, max int
var isSequence bool
for i := 0; i+size <= len(sequence); i++ {
if sequence[i:i+size] == word {
matches++
i += size - 1
isSequence = true
} else {
if is... |
// 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 perf provides utilities to build a JSON file that can be uploaded to
// Chrome Performance Dashboard (https://chromeperf.appspot.com/).
//
// Measurements processe... |
// Copyright 2020 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, ... |
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func main() {
// c = 1
var startA = 0
const finishLength int = 100
var even, finished bool
instructions := strings.Split(input, "\n")
for !finished && startA < 1000 {
var a, b, c, d int
var p int
startA++
a = startA
output := make([]byte, f... |
package lc
import "sort"
// Time: O(n logn)
// Benchmark: 28ms 6.8mb | 80% 19%
func countGoodRectangles(rectangles [][]int) int {
min := func(r []int) int {
if r[0] < r[1] {
return r[0]
}
return r[1]
}
sort.Slice(rectangles, func(i, j int) bool {
r1 := min(rectangles[i])
r2 := min(rectangles[j])
... |
package main
import (
"fmt"
)
func main() {
slice := make([]int, 10)
for i, _ := range slice {
slice[i] = i + 1
}
fmt.Println(slice)
reverse(slice)
fmt.Println(slice)
slice = make([]int, 5)
for i, _ := range slice {
slice[i] = i + 1
}
fmt.Println(slice)
reverse(slice)
fmt.Println(slice)
slice = ma... |
package apimodel
// SubmitMeasurementRequest is the SubmitMeasurement request.
type SubmitMeasurementRequest struct {
ReportID string `path:"report_id"`
Format string `json:"format"`
Content interface{} `json:"content"`
}
// SubmitMeasurementResponse is the SubmitMeasurement response.
type SubmitMeasu... |
package api
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"
"github.com/brocaar/lorawan"
jwt "github.com/dgrijalva/jwt-go"
"google.golang.org/grpc/codes"
"google.golang.org/grpc"
"github.com/brocaar/loraserver/api/gw"
"github.com/brocaar/loraserver/api/ns"
"github.com/brocaar/loraserver/inte... |
package toy
const baseFragmentShader = `
#version 330 core
out vec4 fragColor;
uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform float iTimeDelta; // render time (in seconds)
uniform int iFrame; ... |
// 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 rgbkbd
import (
"context"
"io/ioutil"
"time"
"chromiumos/tast/ctxutil"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromium... |
package data
import (
"fmt"
"net/url"
"os"
)
func NewSite(root string, virtualPaths []string, replaceRoots []string, sitemap string, headers Headers, urlFilename, errorFilename string, timeout, retryLimit int) (*Site, error) {
site := new(Site)
site.Root = root
site.Timeout = timeout
site.RetryLimit = retryLim... |
package main
import "fmt"
type person struct {
first string
last string
age int
}
func main() {
x := person{
first: "Rudi",
last: "Visagie",
age: 25,
}
x.speak()
}
func (p person) speak() {
fmt.Println("My Name is:", p.first, p.last, "and I am ", p.age, " years old")
}
|
package main
import (
"fmt"
"io"
"os"
)
// Echo prints its command line arguments
func Echo(w io.Writer, args []string) {
var s, sep string
for i := 1; i < len(args); i++ {
s += sep + args[i]
sep = " "
}
fmt.Fprintln(w, s)
}
func main() {
Echo(os.Stdout, os.Args)
}
|
// Copyright (c) 2016-2019 Uber Technologies, 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... |
package main
import (
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/bwmarrin/discordgo"
)
var (
svcEC2 *ec2.EC2
)
func init() {
region := os.Getenv("AWS_REGION")
if len(region) == 0 {... |
package main
import (
"sync/atomic"
"fmt"
)
func main() {
var a int32 = 3
b := atomic.AddInt32(&a,3)
fmt.Printf("a is %d, b is %d\n",a,b)
}
|
package webhook
import (
"testing"
"github.com/Dynatrace/dynatrace-operator/src/cmd/config"
cmdManager "github.com/Dynatrace/dynatrace-operator/src/cmd/manager"
"github.com/stretchr/testify/assert"
)
func TestWebhookCommandBuilder(t *testing.T) {
t.Run("build command", func(t *testing.T) {
builder := NewWebho... |
package api
import (
"github.com/Tnze/go-mc/data"
pk "github.com/Tnze/go-mc/net/packet"
)
type Hand int32
const (
MainHand Hand = iota
OffHand
)
func (c *Client) Chat(msg string) {
c.SendPacket(pk.Marshal(data.ChatMessageServerbound, pk.String(msg)))
}
func (c *Client) ToggleFly(enable bool) {
if enable {
... |
package core
// Plugin modes
const (
Docker = "docker"
Kubernetes = "kubernetes"
SwarmMode = "swarm-mode"
Test = "test"
)
|
package main
import "fmt"
func main() {
var a [3]string
fmt.Println("a:", a)
// Set using index
a[1] = "Hello"
fmt.Println("a:", a, "a[1]: ", a[1]) // Get using index
a[0] = "Hi!"
fmt.Println("a:", a, " Length: ", len(a)) // Get Length
// Declare and initialize together
b := [5]int{1, 2, 3, 4, 5}
fmt.Pr... |
package permission
import (
"log"
)
//Session interface hooks up registering Providers and answering questions about Roles and Permissions
type Session interface {
Name() string
SetName(name string)
RoleProviders() []RoleProvider
RegisterRoleProvider(roleProvider RoleProvider) error
RoleProviderFor(profileName... |
package echarge
const (
ModeEco = "eco"
ModeManual = "manual"
)
|
package bigtable
import (
"cloud.google.com/go/bigtable"
"context"
"encoding/json"
"fmt"
"github.com/mattwelke/manydocs/utils"
)
const (
IDPropName = "_id"
)
func (service DocService) SaveDoc(newDoc map[string]interface{}, newDocQueryPrefixes []string) (string, error) {
newDocID := utils.NewID()
newDoc[IDPro... |
package generator
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"github.com/benbjohnson/megajson/generator/decoder"
"github.com/benbjohnson/megajson/generator/encoder"
)
var extregexp = regexp.MustCompile(`\.go$`)
// Generator generates encoders and deco... |
package ws
import "github.com/gorilla/websocket"
//Hub alacen de clientes websocket
type Hub struct {
clients map[string]*user
broadcast chan []byte
}
var hub = &Hub{clients: make(map[string]*user)}
//GetHub devuelve el hub
func GetHub() *Hub {
return hub
}
//IsConnect devuelve el estado de un usuario, conect... |
package gothic
import (
"net/http"
"syscall"
"testing"
"time"
"github.com/jrapoport/gothic/config"
"github.com/jrapoport/gothic/hosts"
"github.com/jrapoport/gothic/test/tconf"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_Main(t *testing.T) {
c := tconf.TempDB(t)
c... |
// Copyright (c) Red Hat, Inc.
// Copyright Contributors to the Open Cluster Management project
//Package managedcluster ...
package managedcluster
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"fmt"
"os"
"k8s.io/klog"
"net/url"
corev1 "k8s.io/api/core/v1"
clusterv1 "github.com/open-cl... |
package myreplication
import (
"bytes"
"reflect"
"testing"
"time"
)
func TestReadPackTotal(t *testing.T) {
mockBuff := []byte{0x03, 0x00, 0x00, 0x0a, 0x01, 0x02, 0x03, 0x03, 0x00, 0x00, 0x0b, 0x04, 0x05, 0x06}
reader := newPackReader(bytes.NewBuffer(mockBuff))
pack, err := reader.readNextPack()
if err != ni... |
package source
const (
DNSSource = "dns"
GoDaddySource = "gds"
NameCheapSource = "ncs"
)
// Source is the interface for domain search sources
type Source interface {
IsAvailable(string) (bool, error)
}
// Get returns a search source
func Get(config interface{}, sourceType string) Source {
switch sourceT... |
package FIFO
import (
"fmt"
"testing"
)
func TestInit(t *testing.T) {
fifoCache := Init(3)
if fifoCache.dList.Capacity == 3 {
t.Log("FIFO Cache init success")
} else {
t.Error("FIFO Cache init failed")
}
}
func TestGet(t *testing.T) {
fifoCache := Init(3)
fifoCache.Put(1)
fifoCache.Put(2)
fifoCache.Pu... |
package main
import "fmt"
func main() {
var s []string
s = append(s, "string1")
s = append(s, "string2")
value, ok := interface{}(s).([]string)
if ok != true {
fmt.Println("value is not a []string")
} else {
fmt.Println("value is []string")
fmt.Println(value)
}
}
|
package solutions
func moveZeroes(nums []int) {
count := 0
for i := 0; i < len(nums); i++ {
if nums[i] != 0 {
nums[count] = nums[i]
count++
}
}
for i := count; i < len(nums); i++ {
nums[i] = 0
}
}
|
// The MIT License (MIT)
//
// Copyright (c) 2014 winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, mo... |
package utils
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/x/bank"
"io/ioutil"
"path/filepath"
)
type TempInput struct {
In []bank.Input `json:"Input"`
}
type TempOutput struct {
Out []bank.Output `json:"Output"`
}
func ParseInput(fp string) ([]bank.Input, error) {
var inputs TempInput
file, err :=... |
package form_test
import (
"strings"
"testing"
"github.com/moltin/gomo/form"
)
func boundary(s string) (b string) {
bits := strings.SplitN(s, "=", 2)
if len(bits) == 2 {
b = "--" + bits[1]
}
return
}
func TestEncode(t *testing.T) {
for _, test := range []struct {
name string
object interface{}
... |
// Copyright 2019 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, ... |
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package merger
import (
"fmt"
"testing"
"github.com/DataDog/datadog-... |
package orm
import (
"github.com/jinzhu/gorm"
)
// ProductDataStore is the product data store
type ProductDataStore struct {
DB *gorm.DB
}
// GetAll returns all the saved products
func (store *ProductDataStore) GetAll() (interface{}, int64, error) {
products := []Product{}
connection := store.DB.Find(&products)
... |
package qmd
import (
"crypto/sha1"
"fmt"
"strings"
"time"
)
// Unique ID generator
var idChan chan string = make(chan string)
func NewID() string {
go generateID()
return <-idChan
}
func generateID() {
h := sha1.New()
c := []byte(time.Now().String())
for {
h.Write(c)
idChan <- fmt.Sprintf("%x", h.Sum(... |
package utils
import (
"io/ioutil"
)
// WriteTmpFile writes data to a temp file and returns the path.
func WriteTmpFile(data string) (string, error) {
f, err := ioutil.TempFile("", "*")
if err != nil {
return "", err
}
defer f.Close()
_, err = f.Write([]byte(data))
if err != nil {
return "", err
}
return... |
package main
import "fmt"
func removeDuplicates(nums []int) int {
if len(nums) == 0 {
return 0
}
i, j := 1, 2
for ; j < len(nums); j++ {
if nums[j] != nums[i-1] {
i++
nums[i] = nums[j]
}
}
fmt.Println(nums[0 : i+1])
return i + 1
}
func main() {
// 0, 0, 1, 1, 2, 2, 3, 3, 4, 4
a := []int{... |
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
const salesTax = 0.06
func main() {
subtotal := 0.00
total := 0.00
value := 0.00
change := 0.00
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("Enter value or command: ")
command, _ := reader.ReadStrin... |
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package netutil
import (
"net"
"runtime"
)
// closeTrackingConn wraps a net.Conn and keeps track of if it was closed
// or if it was leaked (and closes it if it was leaked).
type closeTrackingConn struct {
net.Conn
}
// TrackClose wra... |
package test
import (
"go_code/execrise/testexec/testexec01/model"
"testing"
)
func TestGetSum(t *testing.T){
flag := model.GetSum()
if flag {
t.Logf("答案正确")
}else {
t.Fatalf("答案错误")
}
} |
package main
import (
"org.milkyway/gravity/commands"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
// make the release version and commit info available to the version command
commands.MercurialCommit = MercurialCommit
commands.ReleaseVersion = ReleaseVersion
commands.Execute()
}
|
// Copyright 2019 liuxiaodong 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 agree... |
package helpers
import (
"github.com/LiveSocket/bot/service"
"github.com/gammazero/nexus/v3/wamp"
)
// IgnoreChannel WAMP call helper for ignoring a channel
func IgnoreChannel(service *service.Service, name string) error {
// Call get channel by name endpoint
_, err := service.SimpleCall("private.channel.ignore",... |
/*
* Created on Wed Feb 27 2019 20:54:22
* Author: WuLC
* EMail: liangchaowu5@gmail.com
*/
// record the number of lights at each row, column, left diagonal and right diagonal
// use hashmap instead of list to avoid memory limit exceeded
func gridIllumination(N int, lamps [][]int, queries [][]int) []int {
row, c... |
package main
import "fmt"
func logMap(cityMap map[string]string) {
// cityMap 是一个引用传递,和 js 一样
for key, value := range cityMap {
fmt.Println("key", key, " value:", value)
}
// 原 map 会被影响到
cityMap["demo"] = "ZYK"
fmt.Println("-==--=--=-=-=--")
}
func main() {
cityMap := make(map[string]string)
cityMap["CH... |
package example
import (
"time"
"github.com/ipiao/metools/creator"
)
// User is user
type User struct {
Name string
Age int `json:"age"`
BirthDay time.Time
creator.People
people *creator.People
}
func (u User) Hello(s string) string {
return "hello"
}
|
package main
import "fmt"
func main() {
funcsPorLetra := map[string]map[string]float64{
"G": {
"Gabriela Silva": 9564.56,
"Guga Pereira": 4566.85,
},
"J": {
"José João": 6566.84,
},
"P": {
"Pedro Junior": 5948.56,
},
}
delete(funcsPorLetra, "P") // deleta todos os valores dentro da chave... |
package main
import (
"fmt"
"strings"
"testing"
)
type tuple struct {
a, b int
}
func TestIsMagic(t *testing.T) {
m := []int{1, 9, 35, 37, 174, 1267, 3562, 6712, 6392, 9263, 9627}
n := []int{10, 12, 18, 175, 1624, 2715, 3261, 6372, 7216, 9876}
for _, i := range m {
if !isMagic(i) {
t.Errorf("failed: isMa... |
package main
import (
"github.com/Rorical/NearDB/src/rpc"
"log"
)
func main() {
ser, err := rpc.NewService()
if err != nil {
panic(err)
}
log.Println("Running Service at :9888")
rpc.RunService(":9888", ser)
}
|
// +build !windows
package main
import (
"fmt"
"os"
"strings"
)
func GetDeviceNumber(deviceName string) string {
fi, err := os.Readlink(fmt.Sprintf("/sys/block/%s", deviceName))
if err != nil {
fmt.Println(err)
return ""
}
// segments := strings.Split(strings.TrimPrefix(fi, "/"), "/")
for _, v := range s... |
package pgiface
/*
链接管理模块
*/
type IConnManager interface {
// Add 添加链接
Add(conn IConnection)
// Remove 删除链接
Remove(conn IConnection)
// Get 根据connID获取链接
Get(connID uint32) (IConnection, error)
// Len 得到当前链接总数
Len() int
// ClearConn 清楚并终止所有链接
ClearConn()
}
|
package viewservice
import "fmt"
import "time"
func main() {
dick := make(map[string]time.Time)
dick["sf"] = time.Now()
fmt.Printf("%v\n", dick["sf"])
} |
package google
import (
"fmt"
"regexp"
"time"
"github.com/protofire/polkadot-failover-mechanism/pkg/helpers/validate"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
// Copied from the official Google Cloud auto-generated client.
ProjectRegex = "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-... |
// Copyright (c) 2018 The MATRIX Authors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php
package miner
import (
"math/big"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/core/types"
"git... |
package rabbitmq
import (
"github.com/streadway/amqp"
)
type Subscriber interface {
Subscribe(handler func(message *Message))
}
func NewSubscriber(options *SubscriberOptions) Subscriber {
conn := NewConnection(&ConnectionOptions{
URI: options.URI,
})
return &subscriber{
conn: conn,
s... |
package internal
import (
"crypto/md5"
"fmt"
)
func trimPrefixPath(s string) string {
ii := []int32(s)
for i, s := range ii {
if s == '.' || s == '/' {
continue
}
return string(ii[i:])
}
return ""
}
func getMd5(s []byte) string {
m := md5.New()
m.Write(s)
return fmt.Sprintf("%x", m.Sum(nil))
}
fun... |
package est_utils
import (
//"github.com/application-research/filclient"
"github.com/libp2p/go-libp2p-core/peer"
//"github.com/application-research/filclient"
"github.com/ipfs/go-cid"
"time"
)
type AddResponse struct {
Cid string
EstuaryId uint64
Providers []string
}
type ContentStatus struct {
Conte... |
// Copyright 2021 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
package forward_test
import (
"encoding/xml"
"strings"
"testing"
"time"
"mellium.im/xmlstream"
"mellium.im/xmpp/forward"
"mellium.im/xmpp/stanza"
)
func Tes... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package arc
import (
"context"
"math"
"path/filepath"
"time"
"chromiumos/tast/common/testexec"
"chromiumos/tast/ctxutil"
"chromiumos/tast/errors"
"chromiumos/tast/l... |
package rotationalcipher
import (
"unicode"
)
// RotationalCipher implements Ceasar cipher with `shiftKey` value
func RotationalCipher(plain string, shiftKey int) string {
var res []rune
for _, r := range plain {
if unicode.IsLetter(r) {
if unicode.IsLower(r) {
res = append(res, 97+(r+rune(shiftKey)-97)%2... |
// Copyright 2018 Istio Authors. 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... |
// Created by Noy Hillel
// https://github.com/noy
// You are free to use/modify this software in your own projects
package tsql
import (
"testing"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func TestNewSQLClient(t *testing.T) {
database, err := sql.Open("mysql", "username:password@tcp(localhost)/databas... |
package main
import (
"flag"
"io"
"log"
"net/http"
"netunnel/message"
"time"
"github.com/gorilla/websocket"
)
var (
addr = flag.String("addr", ":88", "wesocket address")
upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
log.Pr... |
package handler
import (
"fmt"
"net/http"
"runtime/debug"
)
type StackTraceMiddlewareHandler struct {
Handler http.Handler
}
func (h StackTraceMiddlewareHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
if p := recover(); p != nil {
body := fmt.Sprintf("%v\n\n%v", p, string(debug.... |
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package extensions_test
import (
"bytes"
"crypto/x509"
"crypto/x509/pkix"
"encoding/gob"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zeebo/errs"
"storj.io/common/id... |
package uintshamir
import (
"fmt"
"crypto/rand"
"math/big"
)
//The SecretSharingScheme defines the parameters for the Shamir secret sharing
type SecretSharingScheme struct {
p int64
t int
n int
}
var standardSetting = SecretSharingScheme { p : 5, t : 2, n : 3}
var wikipediaExample = SecretSharingScheme { p : 1... |
// 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 arcappcompat will have tast tests for android apps on Chromebooks.
package arcappcompat
import (
"context"
"time"
"chromiumos/tast/common/android/ui"
"chromi... |
// 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 smb
import (
"fmt"
"strings"
)
// Config represents the enter smb.conf file with a [global] section and 1 or
// more file shares.
type Config struct {
global *Se... |
package main
import (
"fmt"
"github.com/fvbock/endless"
"go-admin-starter/middleware/jwt"
"go-admin-starter/routers"
"go-admin-starter/utils"
"go-admin-starter/utils/config"
"log"
"net/http"
"runtime"
"syscall"
)
func main() {
conf := config.New()
utils.LogSetup()
jwt.SetSignKey(conf.App.JwtSecret)
rou... |
// Package main ...
package main
import (
"path/filepath"
"github.com/go-rod/rod/lib/utils"
)
var slash = filepath.FromSlash
func main() {
build := utils.S(`// Package assets is generated by "lib/assets/generate"
package assets
// MousePointer for rod
const MousePointer = {{.mousePointer}}
// Monitor for rod
c... |
package util
import "sort"
func copyInts(ints []int) []int {
newInts := make([]int, len(ints))
copy(newInts, ints)
return newInts
}
func reverseInts(ints []int) []int {
ints = copyInts(ints)
i := 0
j := len(ints) - 1
for i < j {
ints[i], ints[j] = ints[j], ints[i]
i++
j--
}
retu... |
type RecentCounter struct {
reqs []int
}
func Constructor() RecentCounter {
return RecentCounter{reqs[]{}}
}
func (this *RecentCounter) Ping(t int) int {
idx := 0
for i := 0; i < len(this.reqs); i++ {
if i >= t - 3000 {
idx = i
break
}
}
this.reqs = this.reqs[idx:]
this.reqs = ap... |
package main
import "fmt"
//函数是引用类型,传递的是地址
//函数作为参数的demo
func demo(iner func(name string)) {
fmt.Println("demo started")
iner("lee")
}
func main() {
demo(func(name string){
fmt.Println("name is ", name)
})
}
|
package main
import (
"net/http"
"testing"
)
func TestHandler(t *testing.T) {
tt := []struct {
name string
request APIRequest
status int
}{
{
name: "Invalid Body",
request: APIRequest{Body: "invalid"},
status: http.StatusBadRequest,
},
{
name: "Check name",
request: APIReques... |
// Copyright 2020 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, ... |
package model
type BaseModel struct {
Id int64 `gorm:"primary_key"`
}
|
package boot
import (
"fmt"
"strings"
"tax-calculator/core"
)
func Bootstrap() {
BootConfig()
BootDatabase()
BootServer()
}
func Run() {
configPort := core.Globals.Config.GetStringSlice("services.app.ports")
ports := strings.Split(configPort[0],":")
port := fmt.Sprintf(":%s", ports[0])
core.Globals.Router.... |
package gelf
import (
"github.com/shanexu/logn/appender/encoder"
"github.com/shanexu/logn/common"
"go.uber.org/zap"
"go.uber.org/zap/buffer"
"go.uber.org/zap/zapcore"
"os"
)
type Encoder struct {
Fields []zapcore.Field
zapcore.Encoder
}
type KeyValuePair struct {
Key string `logn-config:"key"`
Value stri... |
package Models
import (
"github.com/jinzhu/gorm"
)
type Device struct {
gorm.Model
Udid string `json:"udid"`
Status int `json:"status"`
Num int `json:"num"`
Sn string `json:"sn"`
Imei string `json:"imei"`
Bt string `json:"bt"`
Wifu string `json:"wifu"`
Ecid ... |
// Copyright (c) 2016-2019 Uber Technologies, 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... |
package provisioning
import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/services/provisioning/datasources"
)
var (
logger log.Logger = log.New("services.provisioning")
)
func StartUp(datasourcePath string) error {
return datasources.Provision(datasourcePath)
}
|
package cherryPacketSimple
type Encoder struct {
}
func (s *Encoder) Encode(typ byte, data []byte) ([]byte, error) {
return nil, nil
}
|
package wrtc
import (
"fmt"
"log"
"github.com/c0re100/go-tdlib"
"github.com/pion/webrtc/v2"
)
var (
peerConnection *webrtc.PeerConnection
mediaEngine webrtc.MediaEngine
closeRTC = make(chan bool, 1)
userBot *tdlib.Client
)
func setup() {
mediaEngine = webrtc.MediaEngine{}
peerConnection = ... |
package main
import (
"./crawler"
)
func main() {
crawler.StartCrawl("https://bbc.co.uk", 3)
//crawler.StartCrawl("https://www.techcrunch.com/", 3)
}
|
package hard
import (
"testing"
"github.com/stretchr/testify/require"
"fmt"
"github.com/herlegs/programQ/golang/util"
"regexp"
)
func TestSubset(t *testing.T) {
dataSet := []struct {
str string
len int
expected []string
}{
{"abc",1, []string{"a", "b", "c"}},
{"abcd",2, []string{"ab", "bc", "cd", "ac"... |
package set3
import (
"bytes"
"cryptopals/set1"
"cryptopals/utils"
"encoding/base64"
"log"
"testing"
)
var base64strings = [40]string{
"SSBoYXZlIG1ldCB0aGVtIGF0IGNsb3NlIG9mIGRheQ==",
"Q29taW5nIHdpdGggdml2aWQgZmFjZXM=",
"RnJvbSBjb3VudGVyIG9yIGRlc2sgYW1vbmcgZ3JleQ==",
"RWlnaHRlZW50aC1jZW50dXJ5IGhvdXNlcy4=",
... |
package extra
import (
"time"
"webserver/models"
)
type Activity struct {
Id int
ImageUrl string
PageUrl string
Title string
Content string
Extra string
Status int
CreatedAt time.Time
UpdatedAt time.Time
}
func GetActivityInfo(id interface{}) (*Activity, error) {
activity := &Activ... |
package api
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
"github.com/go-chi/chi"
"github.com/porter-dev/porter/internal/analytics"
"github.com/porter-dev/porter/internal/auth/token"
"github.com/porter-dev/porter/int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.