text stringlengths 11 4.05M |
|---|
package pubsub
import (
"fmt"
"io"
"github.com/gorilla/websocket"
"github.com/tomatorpg/tomatorpg/models"
)
// ChanColl is the abstraction of a collection of channels
type ChanColl interface {
LoadOrOpen(id uint) Channel
Close(id uint)
}
// Channel is the abstraction for a pubsub channel
type Channel interfac... |
package application_test
import (
"bytes"
"errors"
"github.com/kkallday/one-off/application"
"github.com/kkallday/one-off/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type ErrBuffer struct{}
func (*ErrBuffer) Write(_ []byte) (int, error) {
return -1, errors.New("failed to write")
}
var _ ... |
package foodchain
import (
"strings"
)
var (
phrases = [][3]string{
{"\n", "\n"},
{"fly", "I don't know why she swallowed the fly. Perhaps she'll die.", ""},
{"spider", "It wriggled and jiggled and tickled inside her.", "to catch the fly."},
{"bird", "How absurd to swallow a bird!", "to catch the spider tha... |
package task
func Init() {
//saTask.Init(saTask.Handle{Spec: "0 */5 * * * *", Name: "mockSyncMdDataDone", HandleFunc: ocpc.MockSyncMdDataDone})
}
|
package corp
import (
"go-interface/config"
"go-interface/depend"
"testing"
"github.com/stretchr/testify/assert"
)
var _, corpAuth, _ = depend.CorpAuth()
var superAuth, _ = depend.SuperAuth()
var commonAuth, _ = depend.CommonAuth()
var otherAuth, _ = depend.OtherAuth()
func TestCorpCreate(t *test... |
package auth
func (s *Service) Register(uniacid int, mobile, pwd, pwdconfirm string) error {
if uniacid == 0 {
return errors.New("无效的应用id")
}
if mobile == "" {
return errors.New("请输入正确的手机号码!")
}
if pwd == "" {
return errors.New("请输入密码!")
}
return s.mclient.MemberCreate(uniacid, mobile, pwd)
}
|
package widgets
import (
"code.google.com/p/draw2d/draw2d"
"github.com/skelterjohn/geom"
"github.com/skelterjohn/go.uik"
"image"
"image/color"
)
type KeyGrab struct {
uik.Block
kbuf image.Image
key string
}
func NewKeyGrab(size geom.Coord) (l *KeyGrab) {
l = new(KeyGrab)
l.Initialize()
l.Size = size
l.... |
package main
import "fmt"
func main() {
a := 100
fmt.Println("The value of A is", a, ".")
fmt.Println("The address of A is:", &a, ".")
fmt.Printf("Which is another way of writing %d", &a)
}
|
package ctrls
import (
"net/http"
"encoding/json"
"io/ioutil"
"log"
"github.com/qowns8/sample-web/models"
)
type NewCanvasForm struct {
Name string `json:"name"`
Intro string `json:"Intro"`
}
func GetMyCanvas (w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("access_token")
user := models.Use... |
// +build !js
package math4g
import (
"github.com/rkusa/gm/math32"
"math"
)
// Scala is a type of element of vector and matrix.
// Scala is a float32 on regular environment, and float64 for Gopher.js
// (https://github.com/gopherjs/gopherjs#performance-tips).
type Scala float32
const (
// Pi is a constant of Pi ... |
// 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 main
import "fmt"
func hasAlternatingBits(n int) bool {
if n <= 2 {
return true
}
b := n & 1
n = n >> 1
for n != 0 {
if b == n&1 {
return false
}
b, n = n&1, n>>1
}
return true
}
func main() {
for i := 0; i <= 10; i++ {
fmt.Println(i, hasAlternatingBits(i))
}
}
|
// 在前面的例子中,我们了解了生成外部进程的知识, 当我们需要在运行的 Go 流程中访问的外部流程时,便可以执行此操作。
// 但是有时候,我们只想用其它(也许是非 Go)的进程,来完全替代当前的 Go 进程。
// 这时,我们可以使用经典的 exec 函数的 Go 的实现
package main
import (
"os"
"os/exec"
"syscall"
)
func main() {
// 在这个例子中,我们将执行 ls 命令。
// Go 要求我们提供想要执行的可执行文件的绝对路径, 所以我们将使用 exec.LookPath 找到它(应该是 /bin/ls)
binary, lookErr :=... |
/*
Copyright 2015 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 in writing, soft... |
// Copyright ©2017 Dan Kortschak. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package ltf8 provides LTF-8 integer encoding.
package ltf8
var pop = [16]byte{
0: 8,
1: 7,
4: 3,
5: 6,
6: 1,
9: 4,
10: 2,
11: 5,
14: 0,
}
//... |
package p_00001_00100
// 20. Valid Parentheses, https://leetcode.com/problems/valid-parentheses/
func isValid(s string) bool {
var stack []rune
for _, r := range s {
if r == '(' || r == '{' || r == '[' {
stack = append(stack, r)
} else {
if stack == nil || len(stack) < 1 {
return false
}
n := l... |
package main
import (
"context"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/registry/etcd"
proto "go-micro-demos/greeter/proto"
"log"
)
type Greeter struct{}
func (g *Greeter) Hello(ctx context.Context, req *proto.HelloRequest, resp *pr... |
package edgerpc
import (
"splitter/lib/cenkalti/rpc2"
"splitter/context"
"splitter/config"
"log"
"splitter/encode"
"errors"
)
// This RPC is called by Upload master WEB APP--> Handle all upload requests
func Split(client *rpc2.Client, args *context.SplitArgs, reply *context.SplitReply)(err error){
log.Println... |
package application
import (
"encoding/json"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
)
type server struct {
router *mux.Router
srv *http.Server
}
// StartApplication sets up the router and middleware
func StartApplication() {
s := server{
router: mux.NewRouter(),
}
s.routes()
port :=... |
package client
import (
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
func WithConnection(apiConnectionDetails *ApiConnectionDetails, action func(*grpc.ClientConn)) {
conn, err := CreateApiConnection(apiConnectionDetails)
if err != nil {
log.Errorf("Failed to connect to api because %s", err)
re... |
// interface{} 引用任何的类型,类似于 ts 中的 any
package main
import "fmt"
type Book struct {
name string
}
func demo(arg interface{}) {
// 有个问题,如何区分万能类型:使用断言
value, ok := arg.(string)
if ok {
fmt.Println(value)
} else {
fmt.Println("no string")
}
}
func main() {
book := Book{"zyk"}
demo(1)
demo("1")
demo(book)... |
package server
import (
"math/big"
"time"
"log"
)
const (
rakePercentage = 1.00
)
type PriceHistory struct {
points []PricePoint
}
var Reserves = map[string]*big.Float{}
type PricePoint struct {
Currency string
Price *big.Float
Time time.Time
}
func (buy PricePoint) sell(amount *big.Float){
}
func (sell... |
// 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 main
import (
"crypto/rsa"
"crypto/x509"
"database/sql"
"encoding/base64"
"encoding/pem"
"errors"
"flag"
"fmt"
//"github.com/davecgh/go-spew/spew"
"github.com/lib/pq"
"github.com/lib/pq/hstore"
. "github.com/wikiocracy/cryptoballot/cryptoballot"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"st... |
package main
import "golang.org/x/net/html"
func nameCounter(counter map[string]int, n *html.Node) map[string]int {
if n == nil {
return counter
}
if n.Type == html.ElementNode {
counter[n.Data]++
}
counter = nameCounter(counter, n.FirstChild)
counter = nameCounter(counter, n.NextSibling)
return counter
}
|
package helm_test
import (
"testing"
"helm.sh/helm/v3/pkg/storage/driver"
"github.com/porter-dev/porter/internal/helm"
"github.com/porter-dev/porter/internal/logger"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/release"
)
func newAgentFixture(t *testing.T, namespace string) *helm.Agent {
t.Helper()
l ... |
package fakes
import (
"sync"
gcpcompute "google.golang.org/api/compute/v1"
)
type TargetHttpProxiesClient struct {
DeleteTargetHttpProxyCall struct {
sync.Mutex
CallCount int
Receives struct {
TargetHttpProxy string
}
Returns struct {
Error error
}
Stub func(string) error
}
ListTargetHttpP... |
// Copyright 2020 Trey Dockendorf
// 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 wri... |
package main
import "fmt"
// Определяем функцию
func update(p *int) {
b := 2
p = &b
}
func main() {
// создаем переменные a и p. Переменная a является числом, а p - содержит адрес переменной a.
var (
a = 1
p = &a
)
// Выводим в stdout значение, содержащееся по адресу, который содержится в переменной p,
//т.... |
package main
import (
"fmt"
)
type Whale interface {
String() string
Jump() int
Swim()
}
type whale struct{
name string
long int
weight int
color string
food string
aveage int
}
func (a *whale)String() string {
return fmt.Sprintf("Whale : %s, color: %s", a.name, a.color)
}
func (a *whale) ... |
package main
import "fmt"
func main() {
s := greet("Jane ", "Doe")
fmt.Println(s)
fmt.Println(greet("Jane ", "Doe"))
}
func greet(fname, lname string) string {
return fmt.Sprint(fname, lname) // Sprint = string print (Its printing to a string instead of standard out)
}
|
package pokergame
import (
"errors"
"github.com/xiaomingping/landlord/poker"
)
type landLordChecker struct{}
func (self landLordChecker) GetSetInfo(set poker.PokerSet) (*SetInfo, error) {
switch set.CountCards() {
case 0:
return nil, errors.New("玩家出牌为空")
//单张
case 1:
return NewSetInfo(LANDLORD_SET_TYPE_SI... |
// MIT License
// Copyright (c) 2020 Tree Xie
// 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, modify, merge,... |
package usage
import (
"fmt"
"DA/4_queue/queue"
"DA/7_graph/graph"
)
// Topo 拓扑排序
type Topo struct {
Am *graph.AdjMatrix
InDegree []int
}
// Output ...
func (topo *Topo) Output() {
topo.Am.Output()
}
// SetEdge ...
func (topo *Topo) SetEdge(tail, head, weight int) {
if topo.Am.SetEdge(tail, head, weight) {
... |
package router
import (
"github.com/16francs/examin_go/interface/handler"
"github.com/16francs/examin_go/interface/middleware"
"github.com/16francs/examin_go/registry"
"github.com/gin-gonic/gin"
)
// Router - ルーティングの定義
func Router() *gin.Engine {
registry := registry.NewRegistry()
// ルーティング
router := gin.Defa... |
package main
import (
"fmt"
"sync"
)
var total struct{
sync.Mutex
value int
}
func worker(wt *sync.WaitGroup) {
defer func() {
wt.Done()
}()
for i:= 0; i <= 100; i++{
total.Lock()
total.value += i
total.Unlock()
}
}
func main() {
var wg sync.WaitGroup
wg.Add(2)
go worker(&wg)
go worker(&wg)
wg.W... |
package encryption
import (
"testing"
"github.com/herumi/bls-go-binary/bls"
"github.com/stretchr/testify/require"
"fmt"
"encoding/hex"
)
func TestMiraclToHerumiPK(t *testing.T) {
miraclpk1 := `0418a02c6bd223ae0dfda1d2f9a3c81726ab436ce5e9d17c531ff0a385a13a0b491bdfed3a85690775ee35c61678957aaba7b1a1899438829f1dc9... |
package main
import "strings"
//331. 验证二叉树的前序序列化
//序列化二叉树的一种方法是使用前序遍历。当我们遇到一个非空节点时,我们可以记录下这个节点的值。如果它是一个空节点,我们可以使用一个标记值记录,例如 #。
//
//_9_
/// \
//3 2
/// \ / \
//4 1 # 6
/// \ / \ / \
//# # # # # #
//例如,上面的二叉树可以被序列化为字符串 "9,3,4,#,#,1,#,#,2,#,6,#,#",其中 # 代表一个空节点。
//
//给定一串以逗号分隔的序列,验证它是否是正确的二叉树的前序序列化。编写一个在... |
package main
// O(n^3) time | O(n) space
func LongestPalindromicSubstring(str string) string {
longest := ""
for i := range str {
for j := i; j < len(str); j++ {
substring := str[i : j+1]
if len(substring) > len(longest) && isPalindrome(substring) {
longest = substring
}
}
}
return longest
}
func... |
package util
import (
"testing"
)
// DefaultPort appends given port to connection if not specified
func TestDefaultPort(t *testing.T) {
expect := "foo:7090"
if uri := DefaultPort("foo:7090", 7090); uri != expect {
t.Errorf("expected %s, got %s", expect, uri)
}
if uri := DefaultPort("foo", 7090); uri != expec... |
package spark
import "github.com/lib/pq"
type Conf struct {
appName string
master string
}
type Master struct {
}
type Worker struct {
}
type Cluster struct {
conn pq.Listener
}
func parseMaster(master string) {
}
|
package main
import (
"fmt"
"unsafe"
)
func slice2String() {
slice := []byte{'1', '2', '3'}
fmt.Println(string(slice))
fmt.Println(*(*string)(unsafe.Pointer(&slice)))
}
func main() {
slice2String()
}
|
package controllers
import (
"net/http"
"wukongServer/models"
"wukongServer/wukong"
)
var (
wk *wukong.Wukong = wukong.DefaultEngine()
)
func init() {
}
type WukongController struct {
BaseController
}
func (wc *WukongController) Documents() {
wc.AjaxSuccess(models.Document{}.Get())
}
func (wc *WukongControl... |
package server
import (
"net/http"
"github.com/gorilla/mux"
"fmt"
"encoding/json"
"log"
//"demos/compiler"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine"
)
// error response contains everything we need to use http.Error
type HandlerError struct {
Error error
Message string
Code ... |
package http
import (
"bufio"
"fmt"
"net"
)
type Request struct {
Method Method
Uri Uri
HttpVersion Version
Headers map[string]string
Body []byte
RemoteAddr net.Addr
}
func ParseRequest(conn net.Conn) (Request, error) {
parser := newRequestParser(bufio.NewReader(conn), bufio.NewWriter(con... |
package cmd
import (
"fmt"
"os"
"github.com/docker/dhe-deploy/gocode/dtr/hubconfig/sanitizers"
"github.com/docker/dhe-deploy/gocode/dtr/ipc/settings/drivers/kv"
"github.com/docker/dhe-deploy/gocode/dtr/shared/dtrutil/kvutil"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
)
var cfgFile string
var rep... |
package main
import (
"fmt"
"kademlia"
"strconv"
"os"
"io/ioutil"
"path/filepath"
)
func Load(k *kademlia.KademliaNode) {
path := "./" + k.MyIP.String() + "-" + strconv.Itoa(int(k.MyPort))
fileList, err := GetFileList(path)
if err != nil {
return
}
for _, i := range fileList {
fmt.Println(i.Name())
... |
package v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// TokenConditionType identifies the token validity condition
TokenConditionType string = "Tokens"
// APITokenConditionType identifies the API Token validity condition
APITokenConditionType string = "APIToken"
// PaaSTokenConditi... |
// Copyright 2021 Comcast Cable Communications Management, 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 ... |
package main
import (
"fmt"
"log"
"net/http"
"text/tabwriter"
)
func (lw *ldapWeb) displayUserInfo(w http.ResponseWriter, r *http.Request) {
u, err := lw.getUserInfo(r)
if err != nil {
http.Error(w, "couldn't parse form: "+err.Error(), http.StatusInternalServerError)
return
}
srch, err := ldapSearch(lw.c... |
package server
import (
"bufio"
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"github.com/gorilla/mux"
protocol "github.com/rareinator/Svendeprove/Backend/packages/protocol"
)
func (s *Server) handleJournalHealth() http.HandlerFunc {
return f... |
package qsort
import (
_sort "sort"
"testing"
)
func TestSort(t *testing.T) {
values := []int32{42, 9, 101, 95, 27, 25}
Sort(values)
isSorted := _sort.SliceIsSorted(values, func(i, j int) bool {
return values[i] < values[j]
})
if !isSorted {
t.Fatal("should be sorted")
}
}
|
package main
import (
"io"
"mime"
"net/http"
"os"
"path/filepath"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rakyll/statik/fs"
_ "github.com/erikh/betl/statik"
)
var staticFilesystem http.FileSystem
func defaultEnv(env, dflt string) string {
if os.Getenv(env) != ""... |
package talib
import (
"math"
)
const (
KRISE = 100
KFALL = -100
KFLAT = 0
)
// Two Crows
func CDL2CROWS(klines []Kline) int {
if klines[0].isYang() && klines[1].isYin() && klines[2].isYin() {
if klines[1].Close > klines[0].Close {
if klines[2].Open > klines[1].Open && klines[2].Close < klines[1].Close {
... |
package worker
import (
gocontext "context"
"time"
"github.com/mitchellh/multistep"
"github.com/travis-ci/worker/context"
"go.opencensus.io/trace"
)
type stepSleep struct {
duration time.Duration
}
func (s *stepSleep) Run(state multistep.StateBag) multistep.StepAction {
ctx := state.Get("ctx").(gocontext.Con... |
package killbill
import (
pbp "github.com/killbill/killbill-rpc/go/api/plugin/payment"
)
func FindPluginProperty(properties []pbp.PluginProperty, key string) string {
for _, prop := range properties {
if key == prop.Key {
return prop.GetValue()
}
}
return ""
}
// TODO Naming...
func FindPluginProperty2(pr... |
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
)
func main() {
i:=0
for i<100{
i=i+1
fmt.Println(i)
go Post("http://localhost:8080/order","","application/x-www-form-urlencoded")
}
}
func Post(url string, data interface{}, contentType string) (content string) {
jso... |
type SignedMessage struct {
message UnsignedMessage
signature Signature
} // representation tuple
|
package main
import (
"os"
"log"
"io"
)
func main() {
file, err := os.OpenFile("test.txt", os.O_RDONLY, 0666)
if err != nil {
log.Fatalln(err)
}
defer file.Close()
byteSlice := make([]byte, 512)
minBytes := 8
// io.ReadAt... |
package main
import "fmt"
func main() {
p := foo()
fmt.Println(p)
q, r := bar()
fmt.Println("\n",q)
fmt.Println("\n",r)
}
func foo() int {
return 7
}
func bar() (i int, s string) {
return 51,"A string"
}
//Hands-on exercise #1
//Review
//functions
//purpose of functions
// **abstract code
// **code reus... |
package main
import "fmt"
func main() {
var a =make(map[int]string)
a[0]="ok";
for k,v:=range a {
fmt.Println(k,v)
}
for _,v:=range a{
fmt.Println(v)
}
m:=map[int]string{1:"a",2:"b"}
fmt.Println(m)
}
|
package util
import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
)
// CreateKubeConfig 构造kubeconfig
// kubeconfig 为空时,使用 in-cluster 配置
// kubeconfig 不为空,使用指定配置(集群外部)
func CreateKubeConfig(kubeconfig string, kubeApiQps float32, kubeApiBurst int) *rest.Config {
var config *rest.Config
... |
package main
import (
"context"
"encoding/json"
"flag"
"io"
"log"
"net"
"os"
"path/filepath"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/identity"
"g... |
package main
import (
"database/sql"
"flag"
"fmt"
"log"
"path/filepath"
"reflect"
"sort"
"strconv"
"time"
"bitbucket.org/liamstask/goose/lib/goose"
)
// global options. available to any subcommands.
var flagPath = flag.String("path", "db", "folder containing db info")
var flagEnv = flag.String("env", "deve... |
package storage
import (
"strconv"
"strings"
"testing"
)
func Test_o1(t *testing.T) {
a := "1,4,5,"
a1 := strings.Split(a, ",")
var (
err error
id int64
)
for _, v := range a1 {
if id, err = strconv.ParseInt(v, 10, 64); err != nil {
t.Log(err)
}
t.Logf("id=%d", id)
}
//t.Logf("len=%d, val=%s"... |
// 统一定义状态机对外暴露功能
package state
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"path/filepath"
"strconv"
"time"
"github.com/golang/protobuf/proto"
"github.com/xuperchain/xupercore/bcs/ledger/xledger/def"
"github.com/xuperchain/xupercore/bcs/ledger/xledger/ledger... |
package valuerange
import "errors"
var (
// ErrParseBytesFailed is returned if information can not be parsed from a sequence of bytes.
ErrParseBytesFailed = errors.New("failed to parse bytes")
)
|
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use ... |
package v2
import (
"encoding/binary"
"errors"
"fmt"
)
type pageHeader interface {
unmarshalHeader([]byte) error
headerLength() int
marshalHeader([]byte) error
}
// DataHeaderLength is the length in bytes for the data header
const DataHeaderLength = 0
// IndexHeaderLength is the length in bytes for the record... |
package main
import "fmt"
type celsius float64
type kelvin float64
type fahrenheit float64
func (c celsius) kelvin() kelvin {
return kelvin(c - 273.15)
}
func (c celsius) fahrenheit() fahrenheit {
return fahrenheit((c * 9.0 / 5.0) + 32)
}
func (k kelvin) celsius() celsius {
return celsius(k + 273.15)
}
func (k... |
package day00
import (
"testing"
"github.com/wistler/aoc-2020/internal/io"
)
func TestSampleData(t *testing.T) {
input := []string{
"",
}
got := part1(input)
want := 0
if got != want {
t.Fatalf("Part 1: Got: %v, but wanted: %v", got, want)
}
got = part2(input)
want = 0
if got != want {
t.Fatalf("P... |
// Copyright 2020 Insolar Network Ltd.
// All rights reserved.
// This material is licensed under the Insolar License version 1.0,
// available at https://github.com/insolar/block-explorer/blob/master/LICENSE.md.
package integration
import (
"bytes"
"testing"
"time"
"github.com/insolar/insolar/insolar"
"github.... |
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
var (
id int
name string
)
type Ticket struct {
id int
event_identifier string
}
func (t Ticket) print() {
fmt.Println(t.id, t.event_identifier)
}
var ticket_list []Ticket
func main() {
fmt.Println("Hello!")
... |
package main
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
)
/*
func main() {
files, err := ioutil.ReadDir("Chapter_12/my_directory")
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.IsDir() {
fmt.Println("Directory:", file.Name())
} else {
fmt.Println("File:", file.Name())... |
package routing
import (
"net/http"
"encoding/json"
"allbooks/decorators"
"github.com/gorilla/mux"
)
const Domain = "http://0.0.0.0:8081"
type Action func(Context)
type Route interface {
Name() string
Method() string
Pattern() string
Action() Action
AroundActions() []Action
}
type BasicRoute stru... |
// Copyright (C) 2016 Space Monkey, 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 account
import (
"github.com/CMedrado/DesafioStone/pkg/domain/entities"
)
func CheckAccountExistence(account entities.Account) error {
if (account != entities.Account{}) {
return ErrAccountExists
}
return nil
}
|
package executor
import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
"github.com/brainicorn/skelp/provider"
"github.com/brainicorn/skelp/skelputil"
)
const (
ErrNoTemplatesFound = "No templates found in %s"
ErrBlankOutputDir = "Output directory not provided"
)
type WalkingExecutor stru... |
package userauth
import (
"context"
"log"
"net/http"
"github.com/go-restit/lzjson"
"github.com/jinzhu/gorm"
"github.com/tomatorpg/tomatorpg/models"
"github.com/tomatorpg/tomatorpg/utils"
"golang.org/x/oauth2"
"golang.org/x/oauth2/github"
)
// GithubConfig provides OAuth2 config for google login
func Github... |
// Copyright (c) 2017 Kuguar <licenses@kuguar.io> Author: Adrian P.K. <apk@kuguar.io>
//
// MIT License
//
// 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
//... |
package run
import "testing"
func TestOrderedFuzzyRegexp(t *testing.T) {
got := orderedFuzzyRegexp([]string{})
if want := ""; got != want {
t.Errorf("got %q, want %q", got, want)
}
got = orderedFuzzyRegexp([]string{"a"})
if want := "a"; got != want {
t.Errorf("got %q, want %q", got, want)
}
got = ordered... |
package snd
// {
// "id": 2511,
// "kind": "user",
// "permalink": "moullinex",
// "username": "Moullinex",
// "uri": "http://api.soundcloud.com/users/2511",
// "permalink_url": "http://soundcloud.com/moullinex",
// "avatar_url": "http://i1.sndcdn.com/avatars-000026871864-c10oaq-large.jpg?2aaad5e"
// }
type Use... |
// 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... |
package main
import "reflect"
// Leetcode 5701. (easy)
func areAlmostEqual(s1 string, s2 string) bool {
m1, m2 := make(map[byte]int), make(map[byte]int)
diff := 0
for i := range s1 {
m1[s1[i]]++
m2[s2[i]]++
if s1[i] != s2[i] {
diff++
}
}
return (diff == 2 || diff == 0) && reflect.DeepEqual(m1, m2)
}
|
package exchange
import (
"encoding/json"
"errors"
"fmt"
"math"
"strconv"
"strings"
"time"
"github.com/polyrabbit/my-token/config"
"github.com/polyrabbit/my-token/http"
"github.com/sirupsen/logrus"
)
// https://www.zb.com/i/developer
const gateBaseApi = "http://data.gateio.io/api2/1/"
type gateClient stru... |
// 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 policy
import (
"context"
"net/http"
"net/http/httptest"
"time"
"chromiumos/tast/common/fixture"
"chromiumos/tast/common/pci"
"chromiumos/tast/common/policy"... |
package main
//实现 Pic 。它返回一个长度为 dy 的 slice,其中每个元素是一个长度为 dx 且元素类型为8位无符号整数的 slice。
// 当你运行这个程序时, 它会将每个整数作为对应像素的灰度值(好吧,其实是蓝度)并显示这个 slice 所对应的图像。
//计算每个像素的灰度值的方法由你决定;几个有意思的选择包括 (x+y)/2、x*y 和 x^y 。
import (
"golang.org/x/tour/pic"
)
func Pic(dx, dy int) [][]uint8 {
// 外层slice
a := make([][]uint8, dy)
for x := range a... |
//
// 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 model
import (
"database/sql"
"time"
)
const (
mysqlPermissionCreateTable = iota
mysqlPermissionInstert
mysqlPermissionDelete
mysqlPermissonGetRole
mysqlPermissonGetAll
mysqlPermissonGetMap
)
type permission struct {
URL string
RoleID uint32
CreatedAt time.Time
}
var (
permissionSQLStri... |
package main
import (
"log"
"github.com/PabloSalvatierra2020/Golang/bd"
"github.com/PabloSalvatierra2020/Golang/handlers"
)
func main() {
if bd.CheckedConnection() == 0 {
log.Fatal("sin conexion a la Base de datos")
return
}
handlers.Handlers()
}
|
// Package launcher for launching browser utils.
package launcher
import (
"context"
"crypto"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
"sync/atomic"
"github.com/go-rod/rod/lib/defaults"
"github.com/go-rod/rod/lib/launcher/flags"
"github.com/go-rod/rod/lib/utils"
... |
// Package custom contains custom API versions
package custom
|
package main
import (
"strings"
"testing"
)
type tuple struct {
n int
q string
}
func TestRacing(t *testing.T) {
for k, v := range map[tuple]tuple{
tuple{9, "########C_##"}: tuple{8, "########/_##"},
tuple{8, "#######_####"}: tuple{7, "#######/####"},
tuple{7, "######_#C###"}: tuple{8, "######_#\\###"}... |
package main
import (
"log"
"net/http"
"gophr.pm/gocql/gocql@3ac1aabebaf2705c6f695d4ef2c25ab6239e88b3"
"gophr.pm/skeswa/gophr@035e5f373426d6fe40f9cd89a615fffedca067fe/common/config"
"gophr.pm/skeswa/gophr@035e5f373426d6fe40f9cd89a615fffedca067fe/common/errors"
)
const (
healthCheckRoute = "/status"
wild... |
// 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 main
import (
"github.com/hzy/web/framework"
"net/http"
)
func UserLoginController(c *framework.Context) error {
c.Json(http.StatusOK, "ok, UserLoginController")
return nil
}
|
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package reservoir
import (
"time"
"github.com/bitmark-inc/bitmarkd/account"
"github.com/bitmark-inc/bitmarkd/blockheader"
"github.com/bitmark-... |
package smartling
import "fmt"
const (
endpointFileStatus = "/files-api/v2/projects/%s/file/status"
)
// GetFileStatus returns file status.
func (client *Client) GetFileStatus(
projectID string,
fileURI string,
) (*FileStatus, error) {
var status FileStatus
_, _, err := client.GetJSON(
fmt.Sprintf(endpointFi... |
package product_category
import (
"inventory-service/modules/product_category/dao"
"inventory-service/modules/product_category/service"
)
func Init() {
dao.Init()
service.Init()
}
|
------------------------------------ 类型 --------------------------------
// ***** 基础类型 *******
整型:
int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, rune, byte, complex128, complex64
byte == int8
浮点型:
float32, float64
复数类型:
complex64, complex128
字符串:
string
字符类型:
rune (int32的别名)
错误类型:
err... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.