text stringlengths 11 4.05M |
|---|
package models
type Hello struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
|
// Package argument provides small set of types
// to parse and interpret command line arguments
package argument
import (
"fmt"
"strconv"
"strings"
)
// Short return true given the arg is a short one
func Short(arg string) bool {
return (len(arg) == 2 &&
arg[0] == byte('-') && arg[1] != byte('-'))
}
// Long r... |
package main
import "fmt"
func defConst(){
const(
str= "strings"
command = 5
)
fmt.Println(str,command)
}
func defNumbers() {
const(
init = iota
start
pause
resume
stop
destroy
)
fmt.Println(init,start,destroy)
}
func main() {
defConst()
defNumbers()
}
|
package LeetCode
import (
"fmt"
"testing"
)
type element struct {
num int
k int
}
func smallestRange(nums [][]int) []int {
var k = len(nums)
var flag = true
var single []element
var resmin int
var resmax int
for flag {
flag = false
ele := element{1000000,1}
//=====================================
... |
package main
import (
"fmt"
"runtime"
)
func main() {
runtime.GOMAXPROCS(2)
var message = make(chan string)
var sayHai = func(msg string){
var data = msg
message <- data
}
go sayHai("soykrucil")
go sayHai("itthi")
go sayHai("SoyItthi")
msg1 := <-message
fmt.Println(msg1)
msg2 := <-message
f... |
package main
import (
"fmt"
)
func spaces(i int) {
if i == 0 {
return
}
spaces(i - 1)
fmt.Print(" ")
}
func num(i int, k int, cond bool) {
if i == 0 || i == k {
return
} else if cond == true {
num(i-1, k, cond)
fmt.Print(i, " ")
} else {
fmt.Print(i, " ")
num(i-1, k, cond)
}
}
func main() {
... |
// Copyright 2013 Walter Schulze
//
// 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... |
//Dette funker ikke
package main
import "fmt"
type struct1 struct {
struct1var1 string
}
type struct2 struct {
*struct1
}
func main() {
var1 := struct1{}
var1.struct1var1 = "Donald"
//var2.struct1var1 = "Dolly"
fmt.Printf("%T\n", var1)
}
|
package filecenter
import (
"context"
"github.com/micro/go-micro"
"log"
"moriaty.com/cia/cia-common/base/constant"
pb "moriaty.com/cia/cia-common/proto/supporter/filecenter"
"moriaty.com/cia/cia-supporter/bean"
"moriaty.com/cia/cia-supporter/dao/filecenter"
"time"
)
/**
* @author 16计算机 Moriaty
* @version 1.... |
package router
import (
"BackendGo/auth"
"BackendGo/server"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
//TODO: fix Error codes
func loginUser(s *server.Server) func(*gin.Context) {
return func(c *gin.Context) {
login := c.Query("login")
pass := c.Query("pass")
if login == "" || pass == "" {
c.JSON(... |
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.
package commands
import (
"fmt"
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func ExampleRunHistory() {
ctx := testCommandContext... |
package main
import (
"DhtCrawler"
"fmt"
"os"
"runtime"
)
func main() {
runtime.GOMAXPROCS(2)
//主进程
master := make(chan string)
//爬虫输出抓取到的hashIds通道
outHashIdChan := make(chan string)
//开启的dht节点
for i := 0; i < 2; i++ {
go func() {
id := DhtCrawler.GenerateID()
dhtNode := DhtCrawler.NewDhtNode(&i... |
package paperswithcode_go
import (
"github.com/codingpot/paperswithcode-go/v2/models"
)
// MethodGet returns a method in a paper.
// See https://paperswithcode-client.readthedocs.io/en/latest/api/client.html#paperswithcode.client.PapersWithCodeClient.method_list
func (c *Client) MethodGet(methodID string) (*models.M... |
package sorting
import (
"fmt"
"testing"
)
// TestMergeSort .
func TestMergeSort(t *testing.T) {
s := []int{9, 8, 7, 6, 5, 4, 3, 2, 1}
result := MergeSort(s)
fmt.Println(result)
}
|
package leetcode
import (
"container/list"
"unicode"
)
/*********************************** 对撞指针题目 ********************************************/
/**
* leetcode 题 125 验证回文串
* https://leetcode-cn.com/problems/valid-palindrome/
* 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写
* 说明:本题中,我们将空字符串定义为有效的回文串
*
* 输入: "A man, ... |
package iobuffer
import (
"encoding/binary"
)
type OutBuffer struct {
data []byte
nLen int
littleEndian bool
}
func NewOutBuffer(size int) *OutBuffer {
if size <= 0 {
size = 1024
}
buf := &OutBuffer{data: make([]byte, size, size), nLen: 0, littleEndian: false}
return buf
}
func (b *OutBuff... |
package main
import "fmt"
// 1. 定义接口、接口默认值
// 2. 实现检测、匿名接口
type itester interface {
test()
string() string
}
type data struct {
}
func (*data) test(){
}
func (data) string() string {
s := "hi fmt.String"
fmt.Println(s)
return s
}
// 3. 超集接口、 子集接口
// 4. 执行机制:
type Ner interface {
a()
b(int)
c(stri... |
// Package report Amazon Seller Utilities API Responses
package report
import (
"encoding/json"
"log"
"net/http"
)
// DownloadReportSuccess A success response from the API
func DownloadReportSuccess(w http.ResponseWriter, version int) error {
apiResponse := DownloadReportAPIResponse{
Version: version,
Success... |
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
const (
checkMark2 = "\u2713" //unicode码 ~ 对号
ballotX2 = "\u2717"
)
func init() {
Routes1()
}
func TestSendJson(t *testing.T) {
t.Log("Given the need to test the SendJSON endpoint.")
{
req, err := http.NewRequest("GET", "/... |
//
// config.go
// Copyright (C) 2019 Grigorii Sokolik <g.sokol99@g-sokol.info>
//
// Distributed under terms of the MIT license.
//
package config
import "go.uber.org/zap"
type Client struct {
Host string `json:"host"`
TimeoutMs int64 `json:"timeoutMs"`
}
type Pool struct {
Size int `json:"size"`
... |
/*
* Copyright (c) 2014-2015, Yawning Angel <yawning at torproject dot org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyr... |
package nv4
import (
"bytes"
"context"
addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
miner "github.com/... |
package playfair_test
import (
"testing"
"github.com/mkamadeus/cipher/cipher/playfair"
)
func TestEncrypt(t *testing.T) {
plain := "TEMUIIBUNANTIMALAM"
key := "JALANGANESHASEPULUH"
cipher, err := playfair.Encrypt(plain, key)
expected := "ZBRSFYKUPGLGRKVSNLQV"
if err != nil {
t.Fatalf("error on playfair enc... |
package main
import (
"fmt"
"go-basic/hsp/customer/model"
"go-basic/hsp/customer/service"
)
type CustomerView struct {
// 接受用户输入
key string
//定义一个CustomerService 字段,主要用于完成对客户信息的各种操作。
customerService *service.CustomerService
}
func (cv *CustomerView) mainMenu() {
forloop:
for {
fmt.Println("---------------... |
/*
Statement
Create a function that will increase a number and that function will be executed by a goroutine inside a for loop (x1000 times). To avoid race conditioning, implement the sync.Mutex and Lock and Unlock inside the increase() function.
Note: Add a time.Sleep() to be able to see the final n
Topics to Pract... |
//go:test !windows
// +test !windows
/*
Copyright © 2022 SUSE 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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or ... |
package main
import (
"fmt"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
)
type Queue struct {
streamers []beep.Streamer
}
func (q *Queue) Add(streamers ...beep.Streamer) {
q.streamers = append(q.streamers, streamers...)
}
func (q *Queue) Stream(samp... |
package PDA
type Stack struct {
contents []int32
}
func (s Stack) Push(character int32) Stack {
s.contents = append([]int32{character}, s.contents...)
return s
}
func (s Stack) Pop() Stack {
if len(s.contents) <= 0 {
return s
}
s.contents = s.contents[1:]
return s
}
func (s Stack) Top() int32 {
if len(s.co... |
package uinput
import (
"bytes"
"encoding/binary"
"fmt"
"os"
"syscall"
)
func ioctl(df *os.File, op, arg uintptr) error {
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, df.Fd(), op, arg)
if err != 0 {
return syscall.Errno(err)
}
return nil
}
func emitEvent(devFile *os.File, typ uint16, code uint16, valu... |
package security
import (
"github.com/gofiber/fiber/v2"
jwtware "github.com/gofiber/jwt/v2"
"github.com/serbanmarti/fiber_rest_api/internal"
)
func ConfigureSecurity(app *fiber.App, env *internal.Environ) {
app.Use(jwtware.New(jwtware.Config{
Filter: func(c *fiber.Ctx) bool {
// Skip authentication for cert... |
package notifier
import (
"log/syslog"
"github.com/jouir/pgterminate/base"
"github.com/jouir/pgterminate/log"
)
// Syslog notifier
type Syslog struct {
sessions chan *base.Session
ident string
format string
priority syslog.Priority
writer *syslog.Writer
}
// NewSyslog creates a syslog notifier
func N... |
package sdk
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
rmTesting "github.com/brigadecore/brigade/sdk/v3/internal/restmachinery/testing" // nolint: lll
metaTesting "github.com/brigadecore/brigade/sdk/v3/meta/testing"
"github.com/stretchr/testify/require"
)
func TestThir... |
package cloudflare
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
)
type CustomNameserverRecord struct {
Type string `json:"type"`
Value string `json:"value"`
}
type CustomNameserver struct {
NSName string `json:"ns_name"`
NSSet int `json:"ns_set"`
}
type CustomNameserverResult struct {
... |
package controller
import (
"encoding/json"
"github.com/13283339616/service"
"github.com/13283339616/vo"
"github.com/gin-gonic/gin"
"net/http"
)
type Hello struct {
}
func (hello *Hello) Load(r *gin.Engine, f func() gin.HandlerFunc) {
userGroup := r.Group("/hello")
{
userGroup.POST("/index", Index)
}
}
fu... |
// Copyright 2023 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 ... |
//
// Copyright 2019 Chef Software, 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 ag... |
package mavlink2
/*
Generated using mavgen - https://github.com/ArduPilot/pymavlink/
Copyright 2020 queue-b <https://github.com/queue-b>
Permission is hereby granted, free of charge, to any person obtaining a copy
of the generated software (the "Generated Software"), to deal
in the Generated Software without restric... |
package main
import (
"net/http"
"github.com/go-chi/chi"
)
func newRouter(a *api) *chi.Mux {
if a == nil {
api, err := newProductionApi()
if err != nil {
panic(err.Error())
}
a = api
}
r := chi.NewRouter()
r.NotFound(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound... |
package main
import (
"bytes"
"net/http"
_ "net/http/pprof"
"strconv"
"sync"
"github.com/rs/zerolog"
"github.com/sirupsen/logrus"
)
var counter = map[string]int{}
var mu sync.Mutex // mutex for counter
var pool = sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
// buf := bytes.NewBuffer(ma... |
package caaa
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document00200102 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:caaa.002.001.02 Document"`
Message *AcceptorAuthorisationResponseV02 `xml:"AccptrAuthstnRspn"`
}
func (d *D... |
package runner
// This file contains implementations of some tar handling functions and methods to add a little
// structure around tar file handling when specifically writing files into archives on streaming
// devices or file systems
import (
"archive/tar"
"io"
"os"
"path/filepath"
"strings"
"github.com/go-s... |
package cbor
import (
"bytes"
"encoding/base64"
"testing"
. "github.com/warpfork/go-wish"
"github.com/polydawn/refmt/tok/fixtures"
)
func Test(t *testing.T) {
testBool(t)
testString(t)
testMap(t)
testArray(t)
testComposite(t)
testNumber(t)
testBytes(t)
testTags(t)
}
func checkEncoding(t *testing.T, se... |
package pie_test
import (
"github.com/elliotchance/pie/v2"
"github.com/stretchr/testify/assert"
"testing"
)
func TestJSONString(t *testing.T) {
for _, test := range jsonTests {
t.Run("", func(t *testing.T) {
assert.Equal(t, test.jsonString, pie.JSONString(test.ss))
})
}
}
|
//check_aws_initialized.go
package main
import (
"log"
"os"
"os/user"
)
func check_aws_initialized() bool {
//CHECK FOR CONFIG FOLDER AND FILE.
usr, err := user.Current()
if err != nil {
log.Fatal( err )
}
path := usr.HomeDir + "/.onecloud/onecloud.cfg"
if _, err := os.Stat(path); os.IsNotExist(e... |
/*
Copyright 2021 CodeNotary, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to i... |
// Copyright 2023 Google LLC. 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 main
import (
"fmt"
"io/ioutil"
"strings"
"time"
"github.com/cenkalti/backoff"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
)
const (
// Confi... |
package gzippool
import (
"bufio"
"bytes"
"io"
"io/ioutil"
"net"
"net/http"
"sync"
"github.com/klauspost/compress/gzip"
)
var (
readerPool = sync.Pool{
New: func() interface{} {
// hack: gzip empty string for init reader
r := bytes.NewReader([]byte{
0x1f, 0x8b, 0x8, 0x0, 0x0, 0x9, 0x6e, 0x88, 0x... |
package policy
import (
"net/http"
"github.com/rightscale/rsc/rsapi"
)
const (
// APIName is used by rsc to display command line help.
APIName = "RightScale Policy API 1.0"
)
// Data structure that holds parsed command line values
var commandValues rsapi.ActionCommands
// RegisterCommands registers all command... |
package model
type AliceSessionID string
type AliceSessionStateID string
const (
AliceStateNew AliceSessionStateID = "NEW"
AliceStateItemAdd AliceSessionStateID = "ITEM_ADD"
)
type AliceSessionState struct {
State AliceSessionStateID
ListName string
ListID TODOListID
ListConfirmed bool
ListA... |
package timeline
import "testing"
func TestValidateData(t *testing.T) {
var unitializedTestData Data
errNo, _ := validateData(&unitializedTestData)
if errNo == 0 {
t.Error("Uninitalized data accepted")
}
}
|
package main
import (
"flag"
"log"
"math"
"os/exec"
"sort"
"strings"
"sync"
"time"
"github.com/BurntSushi/toml"
"github.com/liaosiwei/autobreak/ping"
)
// GetByPercentile will get the data from the percentile value of data,
// the parameter percentile ranges from 1 to 100 as integer
func Percentile(data []... |
package main
type ListNode struct {
Val int
Next *ListNode
}
func mergeKLists(lists []*ListNode) *ListNode {
heap := NewBinaryHeap()
for _, node := range lists {
if node != nil {
heap.Push(node)
}
}
dummy := ListNode{}
tail := &dummy
// 每次取一个、放一个
for !heap.IsEmpty() {
// 堆中的最小值
val := heap.Pop()... |
// Copyright 2019 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 security
import (
"context"
"fmt"
"sort"
"strings"
"time"
"cloud.google.com/go/datastore"
)
type GaePicklistStore struct {
client *datastore.Client
ctx context.Context
expires time.Time
picklists map[string]map[string]map[string]PicklistItem //host -> picklist -> values
}
func NewGaePic... |
// +build !ci
package ykoath
import (
"fmt"
"time"
)
func Example() {
oath, _ := New()
// fix the clock
oath.Clock = func() time.Time {
return time.Unix(59, 0)
}
defer oath.Close()
// enable OATH for this session
_, _ = oath.Select()
// add the testvector
_ = oath.Put("testvector", HmacSha1, Totp, ... |
package main
import (
"bufio"
"fmt"
"github.com/streadway/amqp"
"io/ioutil"
"os"
"strings"
"time"
)
var AMQPConnection *amqp.Connection
var AMQPChannel *amqp.Channel
func failOnError(err error, msg string) {
if err != nil {
panic(fmt.Sprintf("%s: %s", msg, err))
}
}
func main() {
argsWithoutProg := os.... |
// Copyright 2023 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 (
"gt2d"
"math/rand"
"time"
)
type Bullet struct {
Rect *gt2d.Rectangle
Boundary *gt2d.Rectangle
CurrentPosition *gt2d.Vector2D
LastPosition *gt2d.Vector2D
Velocity *gt2d.Vector2D
}
func NewBullet(boundary *gt2d.Rectangle) *Bullet {
rand.Seed(time.Now().UTC().... |
package config
import (
"os"
"path"
"github.com/appditto/pippin_nano_wallet/libs/config/models"
"github.com/appditto/pippin_nano_wallet/libs/utils"
"github.com/creasty/defaults"
"gopkg.in/yaml.v3"
)
func ParsePippinConfig() (*models.PippinConfig, error) {
// Get pippin config path
pippinConfigPath, err := ut... |
package Problem0475
import (
"sort"
)
func findRadius(houses []int, heaters []int) int {
if len(houses) == 0 {
return 0
}
res := 0
sort.Ints(houses)
sort.Ints(heaters)
iHeater := sort.SearchInts(heaters, houses[0])
for iHouse := 0; iHouse < len(houses); iHouse++ {
for iHeater < len(heaters) && houses[... |
package main
import (
"code.cloudfoundry.org/bytefmt"
"fmt"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/monitoring/v3"
"os"
"time"
)
var (
startTime = time.Now().UTC().Add(-time.Hour * 2)
endTime = time.Now().UTC()
)
func ... |
package interpol
import (
"errors"
"io"
"strings"
"testing"
)
func toUpper(key string, w io.Writer) error {
w.Write([]byte(strings.ToUpper(key)))
return nil
}
func TestWithFunc(t *testing.T) {
str, err := WithFunc("hello {test}!!!", toUpper)
if err != nil {
t.Fatal(err)
}
if str != "hello TEST!!!" {
t.... |
package example
import (
"fmt"
"strconv"
"strings"
)
// This layer wil handle the business proccess/any logic that happen in your app
func logicExample(input string) (int, error) {
toNum, err := strconv.Atoi(input)
if err != nil {
return 0, err
}
return toNum + 42, nil
}
func Solution(N int) int {
// wri... |
// Copyright 2018 Authors of Cilium
//
// 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 ... |
package android
import (
"reflect"
"testing"
"github.com/google/blueprint"
)
var visibilityTests = []struct {
name string
fs map[string][]byte
expectedErrors []string
effectiveVisibility map[qualifiedModuleName][]string
}{
{
name: "invalid visibility: empty list",
fs:... |
package main
import (
"fmt"
)
type solution struct{}
func main() {
solution := solution{}
a, b := solution.Read()
result := solution.Process(a, b)
solution.Print(result)
}
func (solution) Read() (int, int) {
var a, b int
fmt.Scanf("%d\n", &a)
fmt.Scanf("%d\n", &b)
return a, b
}
func (solution) Process(a, ... |
package ecc
import (
// "./ecc"
sha "crypto/sha256"
"math/big"
"testing"
// "fmt"
// "hash"
)
func TestPointOperations(t *testing.T) {
C := NewCurve()
curve_name := "secp256k1"
C.GetCurve(curve_name)
if C.name != "secp256k1" {
t.Errorf("Failed loading curve %s", curve_name)
}
k := new(big.Int)
Q... |
package byopenwrt
import (
"bylib/byutils"
"github.com/go-cmd/cmd"
"path/filepath"
"time"
)
func Reset()error {
aps:=cmd.NewCmd("reboot")
//等待aps完成
status := <-aps.Start()
if status.Error!=nil{
return status.Error
}
return nil
}
func ResetAfter(delayS int) {
time.AfterFunc(time.Duration(delayS)*time... |
package cmd
import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/go-amino"
dbm "github.com/tendermint/tm-db"
"log"
)
var cdc = codec.New()
var queryTxCmd = &cobra.Command{
Use: "txs [ha... |
package testapplication
import (
"github.com/cosmos/cosmos-sdk/codec"
)
// RegisterCodec registers concrete types on wire codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgTransmitBol{}, "testapplication/TransmitBol", nil)
cdc.RegisterConcrete(MsgCreateBol{}, "testapplication/CreateBol", nil)
... |
package main
import "fmt"
func main() {
for i := 0; i <= 140; i++ {
fmt.Println(i, " - ", string(i), " - ", []byte(string(i)))
// Take the string and convert it into bytes
// there will be a list of byte for each character
// CONVERT NOT CAST
}
}
|
package main
import (
"OnlineShop/controllers"
_ "OnlineShop/routers"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)
/*
在创建数据库时同步执行这个函数
*/
func InitData() {
orm.RunSyncdb("default", false, true)
o := orm.NewOrm()
//添加一个用户
_, err := o.Raw("insert i... |
package riverntorch
//
// NewFastestBearerApproach returns the object of fastestBearerApproach
//
func NewFastestBearerApproach(crossers RiverCrossers) *fastestBearerApproach {
f := &fastestBearerApproach{
NewBaseApproach(crossers),
}
f.solution.approachName = f.GetName()
return f
}
//
// fastestBearerApproach ... |
package testdata
import (
"github.com/taktakty/netlabi/models"
)
var SiteTestData = []models.Site{
{
Name: "test name 1",
Status: 1,
PostalCode: "111-1111",
PhoneNumber: "111-1111-1111",
Address: "test address 1",
Note: "test note 1",
},
{
Name: "test name 2",
Status... |
package postapp
import (
"net/http"
"github.com/zenazn/goji/web"
)
func TestMiddleware(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("test-header", "test/value")
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
// Copyright 2018 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 httpserver
import (
"net/http"
"time"
)
func NewServer(addr string, handler http.Handler) *http.Server {
return &http.Server{
Handler: handler,
Addr: addr,
ReadTimeout: 180 * time.Second,
ReadHeaderTimeout: 180 * time.Second,
WriteTimeout: 180 * time.Second,
}
}
|
package armor
import "strings"
// ResolveArmorClass resolves a given string to an EArmorClass.
func ResolveArmorClass(str string) EArmorClass {
words := strings.Split(str, " ")
for _, word := range words {
if class, ok := armorClasses[word]; ok {
return class
}
}
return ""
}
// ResolveMaterial resolves ... |
package cryptopals
var freqEn = map[byte]float64{
'e': 12.702, 't': 9.056, 'a': 8.167, 'o': 7.507, 'i': 6.966, 'n': 6.749,
's': 6.327, 'h': 6.094, 'r': 5.987, 'd': 4.253, 'l': 4.025, 'c': 2.782,
'u': 2.758, 'm': 2.406, 'w': 2.361, 'f': 2.228, 'g': 2.015, 'y': 1.974,
'p': 1.929, 'b': 1.492, 'v': 0.978, 'k': 0.77... |
package rabbitHelper
import (
"github.com/skrip42/grabbitLayer/internal/config"
"github.com/streadway/amqp"
)
var isConnected = false
var connection *amqp.Connection
var isChannel = false
var channel *amqp.Channel
//singleton connection
func getConnection() (*amqp.Connection, error) {
if !isConnected {
... |
package constant
const HTTP_STATUS_200 = 200
const JSON_CODE_SUCC = "1000"
const JSON_CODE_ERROR = "1001"
const JSON_CODE_FAIL = "1002"
|
package registry
import (
"context"
"io"
digest "github.com/opencontainers/go-digest"
)
// Service provides access to a remote registry image repositories
type Service interface {
GetBlob(ctx context.Context, repository string, d digest.Digest) (io.ReadCloser, Blob, error)
GetManifest(ctx context.Context, repos... |
package sctransaction
import (
"fmt"
"github.com/iotaledger/wasp/packages/coretypes/requestargs"
"io"
"time"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/wasp/packages/coretypes"
"github.com/iotaledger/wasp/packages/coretypes/cbalances"
"github.com/iotaledger/... |
package resource
import (
"os"
"strings"
"github.com/chronojam/aws-pricing-api/types/schema"
"github.com/olekukonko/tablewriter"
)
func GetEc2Price(instantType string, opsys string, tenancy string) {
ec2 := &schema.AmazonEC2{}
err := ec2.Refresh()
if err != nil {
panic(err)
}
table := tablewriter.NewWrit... |
// Copyright 2019 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agre... |
/*
Copyright IBM Corporation 2020
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, software
di... |
package utils
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// Blockchain is a generalized interface for interacting with the ethereum blockchain
// it satisfies all functions required by the ethclient, and... |
package btrfs
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
"./fs"
"./loop"
)
func TestIsSubvolume(t *testing.T) {
b, err := IsSubvolume(".")
if err != nil {
t.Fatal(err)
}
t.Log(b)
}
func TestSubvolume(t *testing.T) {
bf, err := backingFile()
if err != nil {
t.Fatal(err)
}
... |
package havener
import (
"net/http"
"github.com/zpatrick/go-config"
"fmt"
"strings"
"sort"
)
type SrvIndex struct {
Cfg *config.Config
RegQuery chan interface{}
}
func NewSrvIndex(cfg *config.Config, rq chan interface{}) SrvIndex {
si := SrvIndex{
Cfg: cfg,
RegQuery: rq,
}
return si
}
func (si *Sr... |
package k3s_iot_demo
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/bettercap/gatt"
"github.com/sirupsen/logrus"
"github.com/yosssi/gmq/mqtt/client"
)
type Device struct {
Name string
MacAddress string
Mqtt Mqtt
}
var MqttCli *client.Client
type Mqtt struct {
Server string
Topi... |
package controller
import (
"errors"
"net/http"
"github.com/appditto/pippin_nano_wallet/apps/server/models/responses"
"github.com/appditto/pippin_nano_wallet/libs/wallet"
"github.com/go-chi/render"
)
// Account handlers, reserved for the handlers that directly interact with the account_ actions
// Create a new... |
package worker_pool
import (
"testing"
"time"
"github.com/inconshreveable/log15"
)
func TestBatcher(t *testing.T) {
t.Parallel()
payloads := []*Payload{
{text: "payload1"},
{text: "payload2"},
}
// Define expectations.
wantQueueLen := 0
wantNumPayloads := 2
// Define config.
cfg := Config{
BatchI... |
// 安装: go get github.com/shirou/gopsutil
// 作用: gopsutil 是python工具库psutil的golang移植版,
// 用来获取各种操作系统和硬件信息,并且屏蔽了各个系统之间的差异
// 参考链接:https://mp.weixin.qq.com/s/LCmFOHQ6Pb2UgeIjqG3cSA
package gopsutiluse
import (
"encoding/json"
"fmt"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shi... |
package client
import (
"context"
"errors"
"mobingi/ocean/pkg/kubernetes/client/nodes"
"mobingi/ocean/pkg/log"
"mobingi/ocean/pkg/storage"
)
var Clusters []string
var Monitors = make(map[string]context.CancelFunc)
func InitClustersAndNodes() error {
storage := storage.NewStorage()
clusterArr, err := storage.A... |
package main
import (
"fmt"
)
func pow(a, b int) (p int) {
p = 1
for b > 0 {
if b&1 != 0 {
p *= a
}
b >>= 1
a *= a
}
return p
}
func shellShort(items []int) {
var (
n = len(items)
gaps = []int{1}
k = 1
)
for {
gap := pow(2, k) + 1
if gap > n-1 {
break
}
gaps = append([]int{... |
package main
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"runtime/debug"
"strings"
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
)
type newResponseWriter struct {
http.ResponseWri... |
package game
import (
"errors"
"fmt"
"github.com/golang/glog"
"math/rand"
"qipai/dao"
"qipai/enum"
"qipai/model"
"qipai/utils"
"time"
"zero"
)
// 发送信息给指定房间的所有坐下的玩家
func SendToAllPlayers(msg *utils.Message, msgId int32, roomId uint) {
ps := dao.Room.PlayersSitDown(roomId)
for _, p := range ps {
pp := Get... |
// +build cgo
/* Copyright (c) 2016 Jason Ish
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this lis... |
package shell
import (
"github.com/tywkeene/gosh/env"
"os"
"os/signal"
)
type Shell struct {
SigChan chan os.Signal
Environment env.Vars
}
var Sh Shell
func (sh *Shell) InitSignalHandler() {
sh.SigChan = make(chan os.Signal, 32)
signal.Notify(sh.SigChan)
}
func (sh *Shell) InitShell() {
sh.InitSignalHa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.