text stringlengths 11 4.05M |
|---|
package protocol
// https://tools.ietf.org/html/rfc7483#section-10.2.2
const (
// StatusActive the object instance is in use. For domain names, it
// signifies that the domain name is published in DNS. For network and autnum
// registrations, it signifies that they are allocated or assigned for use in
// operati... |
package objectstorage
import (
"sync"
"sync/atomic"
"github.com/iotaledger/hive.go/kvstore"
"github.com/iotaledger/hive.go/objectstorage/typeutils"
"github.com/iotaledger/hive.go/runtime/syncutils"
"github.com/iotaledger/hive.go/runtime/timed"
)
type CachedObject interface {
Key() []byte
Exists() bool
Get()... |
package main
import (
"fmt"
"sort"
)
type sortRunes []rune
func (s sortRunes) Less(i, j int) bool {
return s[i] < s[j]
}
func (s sortRunes) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortRunes) Len() int {
return len(s)
}
func SortString(s string) string {
r := []rune(s)
sort.Sort(sortRunes(r))
re... |
package list
import (
"fmt"
"github.com/GAQF202/servidor-rest/Structs"
)
//STRUCT PARA RETORNAR LOS INVENTARIOS
type InventoryType struct {
Tienda string
Departamento string
Calificacion int
Products []Structs.Product
}
// STRUCT QUE QUE RECIBE LAS TIENDAS
type Mytype struct {
Datos []struct {
In... |
// 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 (
pb "hello-grpc/hello"
"log"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const (
addr string = "127.0.0.1:50051"
)
func main() {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
c := pb.NewHelloServiceClient(conn... |
package main
import "math"
// todo
// 硬币数量没有限,子问题之间没有相互制约,互相独立
// 迭代解法
func coinChange(coins []int, amount int) int {
dp := make([]int, amount+1)
for i := 0; i < len(dp); i++ {
// dp[i] = 666
dp[i] = math.MaxInt // 注意:初始化为amount+1或者math.MaxInt(最多不会超过amount+1个,不要初始化为666)
}
dp[0] = 0
for i := range dp {
for... |
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package enterprise
import (
"context"
"strings"
"time"
"chromiumos/tast/common/perf"
"chromiumos/tast/common/tape"
"chromiumos/tast/ctxutil"
"chromiumos/tast/remote/... |
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package kioskmode provides ways to set policies for local device accounts
// in a Kiosk mode.
package kioskmode
import (
"bufio"
"bytes"
"context"
"encoding/binary"
... |
package message
import (
"asyncapi/model"
"asyncapi/transport"
)
// TurnOnOff is used to command a particular streetlight to turn the lights on or off.
type TurnOnOff struct {
transport.Message
// ContentType indicates the specified MIME type for this message. If empty, the defaultContentType should be used
Co... |
package search
import (
"os"
"path/filepath"
"strings"
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
)
type JsonDashIndex struct {
path string
items []*JsonDashIndexItem
}
type JsonDashIndexItem struct {
TitleL... |
package types
type P struct {
FirstName string
LastName string
}
|
package main
import (
"fmt"
)
func main() {
x := []string{"a", "b", "c", "d", "e", "f", "g"}
fmt.Println(x)
fmt.Println(x[2]) // get data from position 2 which is c
fmt.Println(x[2:4]) // get data from postion 2 to 4 -1 which is 3 and result is c,d
}
|
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"lovehome/models"
)
type UserSessionController struct {
beego.Controller
}
func (this *UserSessionController) RetData(resp interface{}) {
this.Data["json"] = resp
this.ServeJSON()
}
func (this *UserSessionController) ReadUs... |
package servicemesh
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"net/url"
"sort"
"strings"
"sync"
"github.com/yourbasic/graph"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes/scheme"
"github.com/zdnscloud/c... |
// Copyright 2018 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package leb128
import (
"bytes"
"fmt"
"math/rand"
"testing"
"time"
)
func TestWriteVarUint32(t *testing.T) {
for _, c := range casesUint {
... |
package initRouter
import (
"blog_api/handler"
"github.com/gin-gonic/gin"
)
func SetupRouter() *gin.Engine {
router := gin.Default()
/**
路由分组
*/
router.LoadHTMLGlob("./templates/*")
router.Static("/statics", "./statics")
router.StaticFile("/favicon.ico", "./favicon.ico")
index := router.Group("/")
{
in... |
package postgresql
import (
"fmt"
"os"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var (
DB *gorm.DB
)
func init() {
psqlTractorServiceUsername := os.Getenv("psql_tractor_service_username")
psqlTractorServicePassword := os.Getenv("psql_tractor_service_password")
psqlTractorServiceHost := os.Getenv("psql_trac... |
// Author: Vivek Nathani
// hello is a command line program which is intended to serve as a
// personal dashboard for myself. This program is not made to be used
// just out of the box for anybody. However, every portion of the source-code
// is customizable, if you know how to write code in Go. The task of this
// pro... |
package model
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSearchFilter_String(t *testing.T) {
defer MockNewSearchKeywords(200)()
testSuites := []*struct {
in *SearchFilter
empty bool
str string
extHash []byte
hash string
}{
{
empty: true,
s... |
// 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 platform
import (
"context"
"os"
"strconv"
"strings"
"time"
"github.com/godbus/dbus/v5"
"chromiumos/tast/common/testexec"
"chromiumos/tast/errors"
"chromi... |
package main
import (
"fmt"
)
type Job struct {
id int
count int
}
type Result struct {
id int
count int
}
func main(){
var worker int = 4
Res := []int{1,2,3,4,5,6,7,8}
result := make(chan Result,1000)
job := make(chan Job,worker)
done := make(chan struct{},worker)
go AddJobs(job,Res)
for i:=0;i<worker;... |
package service
import (
"encoding/json"
)
type http struct {
Name string `json:"name"`
Method string `json:"method"`
Path string `json:"path"`
}
type server struct {
// TODO: 增加接口调用超时
Key string `json:"key"`
Service string `json:"service"`
Host string... |
// Copyright 2021 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... |
// Copyright (C) 2017 Michał Matczuk
// Use of this source code is governed by an AGPL-style
// license that can be found in the LICENSE file.
package tunnel
import "time"
var (
// DefaultTimeout specifies a general purpose timeout.
DefaultTimeout = 10 * time.Second
// DefaultPingTimeout specifies a ping timeout.... |
package local
import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
)
type Local struct {
dir string
}
func NewLocal(dir string) (*Local, error) {
st, err := os.Stat(dir)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
if err := os.MkdirAll(dir, 0777)... |
package lc
// Time: O(n+m)
// Benchmark: 8ms 6.2mb | 100% 62%
type Employee struct {
Id int
Importance int
Subordinates []int
}
func getImportance(employees []*Employee, id int) int {
var total int
var search func(id int)
search = func(id int) {
for _, e := range employees {
if e.Id == id {
... |
// Copyright 2016 David Lechner <david@lechnology.com>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"github.com/ev3dev/lmsasm/assembler"
"github.com/ev3dev/lmsasm/bytecodes"
"github.com/ev3dev/lmsasm/parser"
"github.com/ev3de... |
package main
import (
"fmt"
"math"
)
var (
n int = 0
sum int = 0
)
func main() {
for n < 1 || n > int(math.Pow(10, 18)) {
fmt.Scan(&n)
}
for n != 0 {
sum += n % 10
n /= 10
if n == 0 && sum/10 != 0 {
n = sum
sum = 0
}
}
fmt.Print(sum)
}
|
package main
import (
"fmt"
"time"
)
func main() {
messages := make(chan string)
go func() {
msg := <- messages
fmt.Println("Answer is ", msg)
}()
for i := 0; i < 3 ; i++ {
fmt.Println(" ",i+1, " second(s)")
time.Sleep(1*time.Second)
}
messages <- "Hi... |
package main
import _ "runtime/cgo"
////////////////////////////////////////////////////////////
// unkarApp
////////////////////////////////////////////////////////////
/**
* アプリケーションエントリーポイント
*/
func main() {
var mw *MainWin
var err error
// メインウィンドウの生成
mw, err = NewMainWin()
if err != nil {
panic(err)
... |
package main
import (
"log"
"os"
)
func main(){
logger := log.New(os.Stderr,"Custom logger:",log.LstdFlags)
logger.Print("toto")
}
|
package models
import (
"log"
"reflect"
"testing"
)
func init() {
log.SetFlags(log.Flags() | log.Lshortfile)
}
func TestRegistry_Unique(t *testing.T) {
r1 := &OUI{Assignment: "00", OrgName: "n1", OrgAddress: "a1"}
r2 := &OUI{Assignment: "00", OrgName: "n2", OrgAddress: "a2"}
r3 := &OUI{Assignment: "30", OrgN... |
package get2ch
import (
"../util"
"fmt" // DEBUG
"io"
"io/ioutil"
"os"
"path"
"time"
)
const (
BOARD_SETTING = "setting"
// 板情報格納ファイル
tBOARD_LIST_NAME = "ita.data"
// スレッド一覧格納ファイル名
tBOARD_SUBJECT_NAME = "subject.txt"
// 板情報格納ファイル名
tBOARD_SETTING_NAME = "setting.txt"
)
type State struct {
fsize int64
... |
package models
//SaveErr : for validation errors
type SaveErr struct {
s string
}
func (e *SaveErr) Error() string {
return e.s
}
|
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockAmount creates an a Amount
func mockAmount() *Amount {
a := NewAmount()
a.Amount = "000001234567"
return a
}
// TestMockAmount validates mockAmount
func TestMockAmount(t *testing.T) {
a := mockAmount()
require.NoError(... |
package criscross
import (
"crypto/md5"
"fmt"
"log"
"time"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
var mongo *mgo.Session
func StorageConnect(str string) error {
for {
conn, err := mgo.Dial(str)
if err == nil {
log.Println("Successfully connected to mongodb")
mongo = conn
return nil
}
... |
package main
import (
"fmt"
"strconv"
"github.com/MasterMeng/calc"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/protos/peer"
)
type SmartContract struct {
}
func (s *SmartContract) Init(stub shim.ChaincodeStubInterface) peer.Response {
return shim.Success(nil)
}
func (s ... |
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
type Jetpack struct {
Name string
ID int
}
type Location struct {
Lat float32
Long float32
Alt float32
}
type JSONTime time.Time
func (t JSONTime) MarshalJSON() ([]byte, error) {
//do your serializing here
stamp := f... |
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package firmware
import (
"context"
"io/ioutil"
"path/filepath"
"chromiumos/tast/common/testexec"
"chromiumos/tast/shutil"
"chromiumos/tast/testing"
)
func init() {
... |
/*
Copyright 2021 The KodeRover 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, s... |
// Copyright 2014 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, ... |
// 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 tlsconfig
import (
"crypto/tls"
"crypto/x509"
)
const (
helloKey = `
-----BEGIN EC PARAMETERS-----
BgUrgQQAIg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDBGGfwhIJdiUiJUVIItqJjEIMmlXxsMa8TQeer47+g+cIZ466rgg8EK
+Mdn6BY48GCgBwYFK4EEACKhZANiAASW//A9iDbPKg3OLkn7yJqLer32g9I5lBKR
tPc/zB... |
package main
import (
"github.com/micro/go-micro/v2"
log "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-plugins/registry/consul/v2"
"helloworld/handler"
"helloworld/proto/helloworld"
"helloworld/subscriber"
)
func main() {
registry := consul.NewRegistry()
// New Service
service := micro.NewServi... |
package fakes
import (
"sync"
awsec2 "github.com/aws/aws-sdk-go/service/ec2"
)
type VpcsClient struct {
DeleteVpcCall struct {
sync.Mutex
CallCount int
Receives struct {
DeleteVpcInput *awsec2.DeleteVpcInput
}
Returns struct {
DeleteVpcOutput *awsec2.DeleteVpcOutput
Error error
}
... |
package allregions
// Region contains cloudflared edge addresses. The edge is partitioned into several regions for
// redundancy purposes.
type AddrSet map[*EdgeAddr]UsedBy
// AddrUsedBy finds the address used by the given connection in this region.
// Returns nil if the connection isn't using any IP.
func (a AddrSet... |
// 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, ... |
package commands
import (
"bytes"
"os"
"runtime"
"strings"
"testing"
"gotest.tools/assert"
"mvdan.cc/sh/v3/interp"
)
// this test implies to cat testFile
func TestCat(t *testing.T) {
f, err := os.CreateTemp(".", "testFile")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
if _, err = f.WriteSt... |
//Package exercise population count
//TODO need to add test function
package exercise
//pc[i] is the population count of i.
var pc [256]byte
func init() {
for i := range pc {
pc[i] = pc[i/2] + byte(i&1)
}
}
//PopCount returns the population count of x. By using range method
// Exercise2.3
func PopCount(x uint64)... |
/*
Copyright 2021 The Machine Controller 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 w... |
package storage
import (
"context"
"fmt"
"io"
"time"
)
// Storage is the interface for storage operation
type Storage interface {
// Get retrieves a file from storage
Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)
// Head retrieves content length... |
package logs
import (
"bufio"
"encoding/json"
"fmt"
"io"
"regexp"
"github.com/pganalyze/collector/output/pganalyze_collector"
"github.com/pganalyze/collector/state"
uuid "github.com/satori/go.uuid"
)
func PrintDebugInfo(logFileContents string, logLines []state.LogLine, samples []state.PostgresQuerySample) {
... |
package domain
import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
)
type BookmarkContentCollector interface {
CollectText(resourceBody io.ReadCloser) (io.ReadCloser, error)
}
type ResourceBodyProvider interface {
GetResourceBody(url string) (io.ReadCloser, error)
}
func NewBookmarkFactory(resourceBodyProvider Re... |
package handlers
import (
"net/http"
"github.com/gorilla/mux"
"github.com/s1ntaxe770r/minotaur/db"
)
// DeleteProject handles removal of projects
func DeleteProject(resp http.ResponseWriter, req *http.Request) {
dbcon := db.Connect()
defer dbcon.Close()
vars := mux.Vars(req)
id := vars["id"]
jrsp := db.Delet... |
package backup
// Harvester VM backup & restore controllers helps to manage the VM backup & restore by leveraging
// the VolumeSnapshot functionality of Kubernetes CSI drivers with built-in storage driver longhorn.
// Currently, the following features are supported:
// 1. support VM live & offline backup to the suppor... |
// Copyright (C) 2017 Google 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 t... |
package db
import (
"sync"
"github.com/bSkracic/similaritipsum/config"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Conn struct {
*gorm.DB
}
var (
db *Conn
once sync.Once
)
func GetConnection() *Conn {
once.Do(func() {
dbCfg := config.GetFromEnv()
tempDB, err := gorm.Open(postgres.Open(dbCfg.ConnS... |
/*
* Copyright 2020 The Dragonfly 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 la... |
// Copyright 2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vgshiny
import (
"image"
"image/color"
"image/draw"
"testing"
"golang.org/x/exp/shiny/screen"
"golang.org/x/mobile/event/key"
"golang.org/x... |
package services
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
"github.com/Aegon-n/sentinel-bot/updates/messages"
"gopkg.in/telegram-bot-api.v4"
)
type RedditPost struct {
Kind string `json:"kind"`
Data Data `json:"data"`
}
type Post struct {
ApprovedAtUtc interface{} `json:"approved_at_utc"`
... |
package main
import (
"fmt"
"strings"
"bufio"
"os"
"io/ioutil"
"strconv"
)
type Bill struct {
name string
items map[string] float64
tip float64
}
func getInput(prompt string, reader *bufio.Reader) (string, error) {
fmt.Print(prompt + ":")
input, err := reader.ReadString('\n')
return strings.TrimSpace(in... |
package main
import "fmt"
func removeSpace(s string, i *int) {
for *i < len(s) && s[*i] == ' ' {
*i++
}
}
func getInt(s string, i *int) int {
res := 0
for *i < len(s) && isDigit(s[*i]) {
res = res*10 + (int(s[*i]) - int('0'))
*i++
}
return res
}
func isDigit(c byte) bool {
return '0' <= c && c <= '9'
}
f... |
package models
import (
"github.com/vivek-yadav/UserManagementService/models/user"
"gopkg.in/mgo.v2/bson"
"time"
)
type App struct {
Id bson.ObjectId `bson:"_id,omitempty" json:"_id"`
Name string `bson:"Name" json:"Name"`
Description string `bson:"Description" json:"Description"`
... |
package main
import(
"fmt"
"strings"
"net"
"strconv"
"regexp"
)
var connectionCount int
var messagePool chan(string)
const (
INPUT_BUFFER_LENGTH = 140
)
type User struct {
Name string
ID int
Initiated bool
/*The initiated variable tells us that User is connected after a connection and announcement.
Let’s ex... |
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"path"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/vharitonsky/iniflags"
"github.com/zubairhamed/canopus"
)
// process flags
func init() {
flag.Usage = usage
inifile := path.Join(os.Getenv("HOME"), ".tradfri.ini")
iniflags.SetConfig... |
package logger
import (
"io/ioutil"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
config "github.com/ezhk/golang-learning/hw12_13_14_15_calendar/internal/config"
)
func TestLogger(t *testing.T) {
t.Run("create logger", func(t *testing.T) {
defer os.Remove("stdout_file")
_ = os.Remove("st... |
package main
import (
"fmt"
"encoding/json"
"reflect"
)
//var jsonBytes = []byte(`[
//{
// "key1":{
// "Item1": "Value1",
// "Item2": 1},
// "key2":{
// "Item1": "Value2",
// "Item2": 2},
// "key3":{
// "Item1": "Value3",
// "Item2": 3},
// "key4":["test1","t... |
package utils
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/cloudposse/atmos/pkg/schema"
)
const (
LogLevelTrace = "Trace"
LogLevelDebug = "Debug"
LogLevelInfo = "Info"
LogLevelWarning = "Warning"
)
// PrintMessage prints the message to the console
func PrintMessage(message string) {
fmt... |
package models
type User struct {
Id uint8 `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Phone string `json:"phone"`
Password string `json:"password"`
}
|
package account
import (
"context"
"errors"
"github.com/jrapoport/gothic/api/grpc/rpc"
"github.com/jrapoport/gothic/api/grpc/rpc/account"
"github.com/jrapoport/gothic/hosts/rpc"
"google.golang.org/grpc/codes"
)
func (s *accountServer) Login(ctx context.Context,
req *account.LoginRequest) (*api.UserResponse, e... |
// 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, ... |
package fakes
import (
"sync"
gcpcompute "google.golang.org/api/compute/v1"
)
type DisksClient struct {
DeleteDiskCall struct {
sync.Mutex
CallCount int
Receives struct {
Zone string
Disk string
}
Returns struct {
Error error
}
Stub func(string, string) error
}
ListDisksCall struct {
s... |
package pold
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"log"
"net/http"
"os"
"strconv"
"strings"
"github.com/CloudyKit/jet"
"github.com/julienschmidt/httprouter"
)
type Server struct {
conf Config
}
type Blog struct {
Title string `json:"title"`
Author string `json:"author"`
URL stri... |
package main
import "fmt"
type Data struct {
value int
dir int // direction 1:left 0:right
}
var loc = -1
var k int //最大可以移动的元素值
func main() {
for {
var n int
fmt.Println("输入需要进行全排列的值: ")
fmt.Scanf("%d", &n)
fmt.Println("可移动元素最大值 排列 方向(1左0右)")
johnsonTrotterAlgorithm(n)
}
}
//init input... |
package test
import (
"os"
"testing"
"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/magiconair/properties/assert"
)
var taxlotsTFOptions = &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../modules/taxlots... |
package main
import (
"fmt"
"time"
)
func main() {
demo02()
singAndDance()
// demo02() // 这里不会执行,因为singAndDance有主协程 死循环逻辑
}
func singAndDance() {
// 共同抢占 CPU 时间轮片
go sing() // 子协程
go dance() // 子协程
// 死循环,不让主协程结束
for {
;
}
}
func sing() {
for i :=1; i <= 100; i++{
fmt.Printf("正在唱歌,隔壁泰山%d\n", i)
... |
package session_test
import (
"fmt"
"io/ioutil"
"os"
"path"
"sort"
"testing"
"github.com/franela/goblin"
. "github.com/onsi/gomega"
"github.com/spacelift-io/spacectl/client/session"
)
func TestProfileManager(t *testing.T) {
g := goblin.Goblin(t)
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })... |
package apigate
import (
"gylib/common/datatype"
"gylib/common/webclient"
"sync"
"gylib/common/rediscomm"
"strings"
)
type AppGate struct {
Token string
User string
Pass string
Url string
Token_url string
Login_url string
Lock sync.Mutex
apikey string
Client *webclient.H... |
package usecase
import (
"errors"
"strconv"
"strings"
"time"
"github.com/Okaki030/hinagane-scraping/domain/model"
"github.com/PuerkitoBio/goquery"
"github.com/shogo82148/go-mecab"
)
// Scraping はまとめ記事のスクレイピング関数をまとめた関数
func Scraping(now string) ([]model.Article, error) {
var err error
var ars, articles []mo... |
package main
import (
analyzer "github.com/Jesse-Cameron/unassignederr"
"golang.org/x/tools/go/analysis/singlechecker"
)
func main() {
singlechecker.Main(analyzer.UnassignedErrAnalyzer)
}
|
// 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 conference
import (
"context"
"fmt"
"regexp"
"strings"
"time"
"chromiumos/tast/errors"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/browser"... |
package model
import (
"time"
"gorm.io/gorm"
)
// Register transactions from the ecom API
type EcomEvent struct {
ID uint `gorm:"primaryKey" faker:"-"`
CreatedAt time.Time `faker:"-"`
UpdatedAt time.Time `faker:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" faker:"-"`
Team string ... |
package kit
// InterfaceTemplate
var InterfaceTemplate = `
{{$schema := .Schema}}
{{$title := ToUpperFirst .Schema.Title}}
package {{ToLower $title}}
import (
"golang.org/x/net/context"
)
const ServiceName = "{{ToLower $title}}"
{{AsComment $schema.Description}} type {{$title}}Service interface { {{range $funcKey... |
/**
* Copyright (c) 2018-present, MultiVAC Foundation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package signature
import (
"crypto/sha256"
"testing"
)
func TestVerifySignature(t *testing.T) {
message := []byte("Heatwave: ... |
package main
import "testing"
func TestSq(t *testing.T) {
for i := 1; i <= 10; i++ {
if r := sq(i * i); r != i {
t.Errorf("failed: sq %d = %d, got %d", i*i, i, r)
}
}
}
func BenchmarkSq(b *testing.B) {
for i := 0; i < b.N; i++ {
sq(i%10 + 1)
}
}
func sq(a int) (r int) {
for r = 1; r*r < a; r++ {
}
r... |
//
// Copyright (c) SAS Institute 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 agre... |
package main
import (
"bytes"
"fmt"
"os"
)
func main() {
//STARTMAIN1, OMIT
names := []string{
"Imre Nagi",
"Foo Bar",
}
var writer bytes.Buffer
for _, name := range names {
n, err := writer.Write([]byte(name))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if n != len(name) {
fmt.Printl... |
// Copyright 2018 Saferwall. All rights reserved.
// Use of this source code is governed by Apache v2 license
// license that can be found in the LICENSE file.
package mcafee
import (
"context"
"regexp"
"strings"
multiav "github.com/saferwall/saferwall/internal/multiav"
"github.com/saferwall/saferwall/internal/... |
/*
Copyright 2014 Huawei Technologies Co., Ltd. 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 la... |
package app
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/lazynpm/pkg/commands"
"github.com/jesseduffield/lazynpm/pkg/config"
"github.com/jesseduffield/lazynpm/pkg/gui"
"github.com/jesseduffield/lazynpm/pkg/i18n"
"github.com/jesseduffield/lazynpm/pkg/updates"
"github.co... |
package main
import "fmt"
func main() {
var big int
var small int
fmt.Println("please enter a double or tripple diget whole number")
fmt.Scan(&big)
fmt.Println("now enter a single diget whole number")
fmt.Scan(&small)
dividend := big/small
remainder := big%small
fmt.Println("Answer:", dividend, "wit... |
package productController
import (
"github.com/gin-gonic/gin"
"github.com/ulule/deepcopier"
"hd-mall-ed/packages/admin/models/productModel"
"hd-mall-ed/packages/admin/models/staticModel"
"hd-mall-ed/packages/common/pkg/adminApp"
"hd-mall-ed/packages/common/pkg/e"
)
func Create(c *gin.Context) {
api := adminApp... |
package gcsexport
import (
"cloud.google.com/go/storage"
"context"
"errors"
"fmt"
"io"
"net/url"
)
func Export(inputReader io.Reader, gcsObject string) (int64, error) {
gcsURL, err := url.Parse(gcsObject)
if err != nil {
return 0, err
}
if gcsURL.Scheme != "gs" {
return 0, errors.New("URL should start w... |
package grove
import (
"bytes"
"context"
"encoding/binary"
"github.com/niolabs/gonio-framework"
"golang.org/x/exp/io/i2c"
"encoding/json"
"fmt"
)
const (
gMps2 = 9.80665
scaleMultiplier = 0.004
dataFormat = 0x31
bwRate = 0x2C
powerCtl = 0x2D
bwRate1600HZ = 0x0F
bwRate800HZ = 0x0E
bw... |
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package storj
import (
"database/sql/driver"
"github.com/zeebo/errs"
)
// ErrSerialNumber is used when something goes wrong with a serial number.
var ErrSerialNumber = errs.Class("serial number")
// SerialNumber is the unique identifi... |
package timex_test
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/socialpoint-labs/bsk/timex"
)
func TestParse(t *testing.T) {
now := time.Now()
testCases := []struct {
dateStr string
valid bool
expected string
}{
{"2016-04-23 12:56", true, "2016-04-... |
package main
import (
"fmt"
"html/template"
"sort"
"strings"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
)
func getWords(scens *map[string]*Scenario) []string {
var b strings.Builder
for name := range *scens {
fmt.Fprintf(&b, "%v ", name)
}
return strings.Spli... |
package leetcode
import (
"fmt"
"testing"
)
type question1 struct {
para1
ans1
}
// para 是参数
// one 代表第一个参数
type para1 struct {
nums []int
target int
}
// ans 是答案
// one 代表第一个答案
type ans1 struct {
one []int
}
func Test_Problem1(t *testing.T) {
qs := []question1{
{
para1{[]int{3, 2, 4}, 6},
ans1{... |
package global
import (
"context"
"database/sql"
"fmt"
"log"
"testing"
"time"
"github.com/go-redis/redis/v8"
)
func TestGetUserCache(t *testing.T) {
redisClient := redis.NewClient(&redis.Options{
Username: "root",
Password: "",
Addr: ":6379",
})
db, err := sql.Open("mysql", "root:123456@tcp(10.2... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.