text stringlengths 11 4.05M |
|---|
package store
import (
"database/sql"
"gorm.io/gorm"
)
// Store interface represents store options
type Store interface {
GetTodos() ([]Todo, error)
AddTodo(todo *Todo) (*Todo, error)
// MarkDone(uint, bool) (Todo, error)
// DeleteTodo(uint) error
}
// Todo model for storing a todo
type Todo struct {
gorm.Mo... |
package snowflake
import (
"fmt"
"testing"
"time"
)
func TestNewSnowFlake(t *testing.T) {
fmt.Println("Testing...")
}
func BenchmarkNewSnowFlake(b *testing.B) {
snow := NewSnowFlake(1, 1)
for i := 0; i < b.N; i++ {
snow.GetID()
}
s := time.Now()
fmt.Println(s)
fmt.Println(s.UnixNano())
fmt.Println(s.Uni... |
/*
* Minio Client (C) 2015 Minio, 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 agr... |
package docker_events
import (
"encoding/json"
"github.com/ActiveState/log"
"io"
"io/ioutil"
"net/http"
"time"
)
const ID_LENGTH = 12
var (
events_url = "http://localhost:4243/events"
containers_url = "http://localhost:4243/containers/json"
)
type Event struct {
Id string `json:"id"`
Status string... |
package main
import (
"flag"
"fmt"
"net"
"regexp"
"strings"
)
//go env -w CGO_ENABLED=0 -w GOOS=android -w GOARCH=arm build -ldflags "-s -w" get_public_ipv6.go
func main() {
public := flag.Bool("public", false, "显示“临时的”公网 IPv6,"+
"该 IPv6 地址是路由器临时分配的,会在一定时间刷新,也是你上网时对外暴露的 IPv6 地址。"+
"此地址重新连接网络后,就会改变")
perm... |
package controller
import (
"github.com/gin-gonic/gin"
"go-bubble/models"
"net/http"
"strconv"
)
func IndexHandler(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
}
func Create(c *gin.Context) {
// 绑定参数
var todo models.Todo
c.BindJSON(&todo)
// 保存并响应
if err := models.Create(&todo); err != nil {
... |
package demo
import (
"bytes"
"encoding/json"
"fmt"
)
type Post struct {
ID int
}
func StructToJson01() {
p1 := Post{ID: 100}
_, err := json.Marshal(p1)
if err != nil {
fmt.Printf("Error %v ", err)
}
}
func StructToJson02() {
p1 := Post{ID: 100}
var buffer bytes.Buffer
json.NewEncoder(&buffer).Encode(&... |
/*
# -*- coding: utf-8 -*-
# @Author : joker
# @Time : 2021/12/1 9:13 上午
# @File : lt_240_搜索二维矩阵.go
# @Description :
# @Attention :
*/
package v2
// 关键,从左下或者右上开始查询
func searchMatrix2(matrix [][]int, target int) bool {
for i, j := 0, len(matrix[0])-1; i < len(matrix) && j >= 0; {
if matrix[i][j] == target {
retur... |
package byutil
import (
"bylib/bylog"
"fmt"
)
func FormatError(msg string,err error)error{
err2:=fmt.Errorf( "%s %s",msg,err.Error())
bylog.Error("%s",err2.Error())
return err2
} |
package main
import (
"flag"
"log"
"math/rand"
"net/http"
"os"
"os/exec"
"strconv"
"github.com/dan-v/dosxvpn"
)
var (
flagCli = flag.Bool("cli", false, "Deploy using CLI. Must define DIGITALOCEAN_ACCESS_TOKEN")
flagDelete = flag.Bool("delete", false, "Delete all dosxvpn instances")
flagRegion = flag.St... |
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func isBalanced(root *TreeNode) bool {
if root == nil || (root.Left == nil && root.Right == nil) {
return true
}
level := 0
result, _ := treeLevel(root, leve... |
package twitch
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"time"
)
var tID string
const accept string = "application/vnd.twitchtv.v5+json"
// SetID => takes clientID and sets variable for use in header
func SetID(clientID string) {
fmt.Println("Setting clientID")
tID = clientID
}
// Get... |
package bccsp
import (
"crypto"
"hash"
)
type Key interface {
Bytes() ([]byte, error)
SKI() []byte
Symmetric() bool
Private() bool
PublicKey() (Key, error)
}
type KeyGenOpts interface {
Algorithm() string
Ephemeral() bool
}
type KeyDerivOpts interface {
Algorithm() string
Ephemeral() bool
}
type K... |
package keeper_test
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/t... |
package relay
import (
"context"
"fmt"
"time"
"google.golang.org/grpc"
"github.com/batchcorp/collector-schemas/build/go/protos/records"
"github.com/batchcorp/collector-schemas/build/go/protos/services"
"github.com/batchcorp/plumber/backends/mqtt/types"
)
// handleMQTT sends a MQTT relay message to the GRPC ... |
package worker
import (
"errors"
"reflect"
)
var (
ErrNotChannel = errors.New("not a channel")
ErrNotReadableChannel = errors.New("not a readable channel")
)
// InputChannelAdapter expects a readable channel of any value as input and
// returns a readable channel of interface values. Items are copied fro... |
// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.
package aws
import (
"context"
"fmt"
"strings"
"sync"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/e... |
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
)
var (
url string
addr string
)
func init() {
flag.StringVar(&url, "url", "http://127.0.0.1:8080", "provide your twirp server base url")
flag.StringVar(&addr, "addr", ":8090", "proxy binding address")
flag.Parse()
}
func handler(w http.ResponseWri... |
/*
// A Duration represents the elapsed time between two instants as
// an int64 nanosecond count. The representation limits the largest
// representable duration to approximately 290 years.
type Duration int64
// Common durations. There is no definition for units of Day or larger
// to avoid confusion across dayligh... |
package day07
import (
"strconv"
"strings"
"../utils"
)
var input, _ = utils.ReadFile("day07/input.txt")
// Bag is a structure of bags
type Bag struct {
id string
content map[string]int
}
var bags []Bag
// ParseLines parses file input
func ParseLines(input []string) {
for _, line := range input {
par... |
/*
Copyright © 2019 BlackRock 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 in writing, softwar... |
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"clair_reporter/clair"
"clair_reporter/reporter"
)
var f string
var teamConfigFilePath string
func init() {
flag.StringVar(&f, "file-path", "", "path to the JSON report from klar")
flag.StringVar(&teamConfigFilePath, "tea... |
package models
import (
"time"
"github.com/uadmin/uadmin"
)
type Справочники struct {
uadmin.Model
Name string
Description string `uadmin:"html"`
TargetDate time.Time
}
|
/*
Copyright 2019 The Kubernetes 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, ... |
/**
*@Author: haoxiongxiao
*@Date: 2019/3/18
*@Description: CREATE GO FILE services
*/
package services
import (
"bysj/models"
"github.com/astaxie/beego/toolbox"
"time"
)
func SyncDashBoard() {
tk := toolbox.NewTask("tk1", "0 0 3 * * *", func() error {
s, _ := time.ParseDuration("-6h")
tx := models.GetMysqlD... |
package config
import (
"encoding/json"
"os"
"github.com/juju/errors"
)
type Config interface {
Values() *Values
}
type FileConfig struct {
values *Values
}
// New loads the configuration values for the app
func NewFileConfig() (*FileConfig, error) {
file, err := os.ReadFile("./config/config.json")
if err !... |
package main
func main(){
for{
tsubscriber :=
messages_listener := tsubscriber.GetMessagesListener()
trigger.On("message-arrived", func() {
// Do Some Task Here.
fmt.Println("Done")
})
}
}
|
package telegram
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/metalmatze/alertmanager-bot/pkg/telegram"
"github.com/stretchr/testify/require"
"gopkg.in/tucnak/telebot.v2"
)
var alertsWorkflows = []workflow{{
name: "AlertsNone",
messages: []telebot.Update{{
Message: &telebot.Message{
Sender: a... |
package fateRPGtest
import (
"testing"
"github.com/faterpg"
)
func TestNewCharacterSheet(t *testing.T) {
pc := faterpg.NewPC()
ch := faterpg.NewCharacterSheet(pc)
if ch == nil {
t.Error("NewCharacterSheet return nil")
}
}
func TestCharacterSheetAttr(t *testing.T) {
name := "Test name"
pc := faterpg.NewNam... |
package mock
import (
"archive/zip"
"io"
"github.com/10gen/realm-cli/internal/cloud/realm"
)
// RealmClient is a mocked Realm client
type RealmClient struct {
realm.Client
AuthenticateFn func(publicAPIKey, privateAPIKey string) (realm.Session, error)
AuthProfileFn func() (realm.AuthProfile, error)
DiffFn ... |
package controllers
import (
"compressor/archiver"
"compressor/db"
"compressor/mailer"
"compressor/models"
"compressor/uploader"
"errors"
"fmt"
"io"
"net/http"
"os"
"gopkg.in/mgo.v2/bson"
)
var currentJam models.Jam
//FetchJam func, fetching a jam by
// a given id
func FetchJam(params *models.ArchivePara... |
package dao
import (
"github.com/SungKing/blogsystem/models/entity"
"github.com/astaxie/beego/orm"
"fmt"
)
type CommentDao struct {
}
func (* CommentDao)GetOne(id int32) entity.Comment {
o:=orm.NewOrm()
comment:=entity.Comment{Id:id}
err:=o.Read(&comment)
if err == orm.ErrNoRows {
fmt.Println("查询不到相关评论")
... |
package main
import (
"net/http"
"time"
"github.com/gorilla/websocket"
"go-push/connection"
)
func main() {
// http://localhost:7777/ws
// 1.路由接口地址
// 2.回调函数-当有请求来的时候这个函数会被回调
// http 配置路由 /ws 接口
// 当客户端调用 /ws 接口 wsHandler函数就会被调用
http.HandleFunc("/ws", wsHandler)
// 启动服务端
// 绑定监听端口对外提供http服务
// 前面配置好了 ... |
package main
import (
"fmt"
"regexp"
)
func main() {
s1 := "/of_course_i_still_love_you"
s2 := "/of_course_i_still_love_you/000"
reg := regexp.MustCompile(`/of_course_i_still_love_you/`)
fmt.Println(reg.FindAllString(s1, -1)) // []
fmt.Println(reg.FindAllString(s2, -1)) // [/of_course_i_s... |
package list
import (
"github.com/devspace-cloud/devspace/pkg/util/factory"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
type SpacesCmd struct {
Name string
Provider string
All bool
Cluster string
}
func newSpacesCmd(f factory.Factory) *cobra.Command {
cmd := &SpacesCmd{}
SpacesCmd := &cob... |
/*
TO OPEN ME PLEASE EXECUTE THE FOLLOWING:
$ go run paraEdu.go
*/
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var alwaysHere = true
scanner := bufio.NewScanner(os.Stdin)
var initial = "\nMe pongo canciones para escribirte.\n"
fmt.Println(initial)
fit := "A veces las cosas no encajan ni a gol... |
package awssns
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/pkg/errors"
"github.com/batchcorp/plumber-schemas/build/go/protos/opts"
"github.com/batchcorp/plumber-schemas/build/go/protos/records"
"github.com/... |
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/bartlettc22/kubeviz-server/server"
)
var listenerPort int
var token string
var s3Bucket string
var s3Key string
func init() {
startCmd.Flags().IntVarP(&listenerPort, "listener-port", "p", 80, "server listener port")
viper.Bi... |
package center
import (
"bytes"
"encoding/json"
"net/http"
"github.com/empirefox/ic-client-one/storage"
"github.com/empirefox/ic-client-one/wsio"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
type Upgrader interface {
Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (... |
// Copyright 2023-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... |
// Copyright 2020 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package canvas
import (
"image"
"image/draw"
)
// ImageData represents the underlying pixel data of an image. It is
// created using the Context.CreateImageD... |
package main
import "fmt"
func main() {
var fruit = [3]string{"Apple", "Durian", "Melon"}
// replace item array
fruit[1] = "Manggo"
fmt.Println("Total Length Array : ", len(fruit))
fmt.Println("List Array : ", fruit)
}
|
package basic
import (
"gonum.org/v1/gonum/mat"
"math"
)
func NewVec(X,Y,Z float64) *mat.VecDense {
return mat.NewVecDense(3, []float64{X, Y, Z})
}
func ZeroVec() *mat.VecDense {
return mat.NewVecDense(3, []float64{0, 0, 0})
}
func ZeroMat() *mat.Dense {
return mat.NewDense(2 , 2, []float64{0, 0, 0, 0})
}
fun... |
/**
* Copyright (c) 2018 ZTE Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and the Apache License 2.0 which both accompany this distribution,
* and are available at http://www.eclipse.org/legal/epl-v10.html
... |
package main
import "fmt"
type Arvore struct {
info int
esq *Arvore
dir *Arvore
}
/* retorna a quantidade de nós que armazenam números pares */
func (a *Arvore) Pares () int {
if(a == nil){
return 0
}
cont := 0
if(a.info % 2 == 0){
cont++
}
cont = cont + a.esq.Pares()
cont = cont + a.dir.Pares()
retu... |
package provisionerbeta
import (
"bytes"
"encoding/json"
"fmt"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"google.golang.org/protobuf/encoding/protojson"
)
func getCommand() cli.Comm... |
/*
* EVE Swagger Interface
*
* An OpenAPI for EVE Online
*
* OpenAPI spec version: 0.4.1.dev1
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
package swagger
// 200 ok object
type GetUniverseStargatesStargateIdOk struct {
Destination GetUniverseStargatesStargateIdDestination `json:... |
package repository
import (
. "2019_2_IBAT/pkg/pkg/models"
"fmt"
"testing"
"github.com/google/uuid"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)
// func TestDBUserStorage_GetFavoriteVacancies_Correct(t *testing.T) {
// db, mock, err := sqlmock.New()
// defer ... |
package cmd
import (
"fmt"
"os"
nc "github.com/edribeirojunior/nats-config-reloader/pkg/nats"
"github.com/spf13/cobra"
)
var hostedZoneName, dnsName, natsObject, natsNamespace string
var natsTimeout int
var rootCmd = &cobra.Command{
Use: "nats-config-reloader",
Short: "Nats Config Reloader",
Long: "Nats C... |
package main
import "fmt"
func main() {
//[null,1,2,1,2,3]
rc := Constructor()
fmt.Println(rc.Ping(642))
fmt.Println(rc.Ping(1849))
fmt.Println(rc.Ping(4921))
fmt.Println(rc.Ping(5936))
fmt.Println(rc.Ping(5957))
}
type RecentCounter struct {
s []int
}
func Constructor() RecentCounter {
return RecentCo... |
package dht
import (
"github.com/footstone-io/socker"
"github.com/vmihailenco/msgpack"
)
type PingReq struct {
User ID
}
type PingResp struct {
ID ID
}
func (dht *DHT) pingHandler(msg *socker.MsgEvent) ([]byte, error) {
req := new(PingReq)
err := msgpack.Unmarshal(msg.Body, &req)
if err != nil {
return nil... |
package caryatid
import (
"archive/tar"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
"github.com/hashicorp/packer/packer"
"github.com/mrled/caryatid/internal/util"
)
// Determine the provider of a Vagrant box based on its metadata.json
// See also https://www.packer.io/docs/... |
package services
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"github.com/constant-money/constant-event/daos"
"github.com/constant-money/constant-event/models"
"github.com/constant-money/constant-web-api/serializers"
"github.com/constant-money/constant-web-api/services/3rd/... |
// Copyright 2016 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... |
package render
import (
"fmt"
"github.com/nsf/termbox-go"
"github.com/siggy/bbox/bbox/color"
)
type Terminal struct{}
func InitTerminal() *Terminal {
return &Terminal{}
}
// TODO: dry up
func (t *Terminal) TBprint(x, y int, msg string) {
for _, c := range msg {
termbox.SetCell(x, y, c, termbox.ColorDefault,... |
package pain
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document00700107 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:pain.007.001.07 Document"`
Message *CustomerPaymentReversalV07 `xml:"CstmrPmtRvsl"`
}
func (d *Document00700107) ... |
package main
// Import the packages
import (
"time"
"net/http"
"strings"
"sync"
"flag"
"bufio"
"os"
"log"
"github.com/fatih/color"
)
// Main
func main () {
// Print the banner
color.Blue(`
_________ ____ ___
\_ ___ \ ___________ _____\ \/ /
/ \ \/ / _ \_ __ \/ ___/\ /
\ ... |
package main
import (
"context"
"fmt"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second)
go watch(ctx, "【监控1】")
chCtx, cl := context.WithCancel(ctx)
go watch(chCtx, "【监控2】")
vCtx := context.WithValue(ctx, "name", "mafeng")
go watch(vCtx, "【监控3】")
time.Sleep(t... |
// -----------------------------------------------------------------------------
// Web package used for encapsulating work with web application.
// -----------------------------------------------------------------------------
package main
import (
"godistributed-rabbitmq/web/controller"
_ "godistributed-rabbitmq/we... |
package scan
import (
"fmt"
"strings"
"testing"
"h12.io/gspec"
// ogdl "github.com/ogdl/flow"
)
const EOF = 0
var _ = gspec.Add(func(s gspec.S) {
describe, given, it, they, and := gspec.Alias5("describe", "given", "it", "they", "and", s)
expect := gspec.Expect(s.FailNow)
describe("patterns", func() {
giv... |
// Copyright 2014 The Sporting Exchange Limited. All rights reserved.
// Use of this source code is governed by a free license that can be
// found in the LICENSE file.
package aggregator
import (
"reflect"
"testing"
"time"
"opentsp.org/cmd/collect-statse/statse"
)
var testStoreWrite = []struct {
in []*statse... |
package main
import (
"log"
"github.com/shaunschembri/restreamer/internal/restreamer"
)
var version string
func main() {
log.Printf("Starting restreamer %s", version)
restreamer.Main()
}
|
package service
import (
"github.com/chanxuehong/wechat/mp/core"
)
type MaterialService struct {
SuggestTodayService
SuggestWeekService
SuggestMonthService
}
func (this *MaterialService) ModifyNews(wcClient *core.Client) {
this.SuggestTodayService.ModifyTodayTbs(wcClient)
this.SuggestTodayService.ModifyTodayGu... |
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package protocol
import (
"github.com/trustbloc/sidetree-core-go/pkg/api/operation"
"github.com/trustbloc/sidetree-core-go/pkg/api/txn"
"github.com/trustbloc/sidetree-core-go/pkg/document"
"github.com/trustbloc/s... |
package helper
import (
"os"
"path/filepath"
"k8s.io/client-go/tools/clientcmd"
)
// GetKubeConfigPath returns the default location of a kubeconfig file
func GetKubeConfigPath() string {
// TODO: handle multiple paths in KUBECONFIG
if fl := os.Getenv("KUBECONFIG"); fl != "" {
return fl
}
home, err := os.Use... |
package truecolor
import (
"bytes"
"image/color"
"testing"
)
func TestFprint(t *testing.T) {
var b bytes.Buffer
tc := New()
tc.Add(NewBackgrond(color.RGBA{255, 0, 0, 255}))
tc.Add(NewForeground(color.RGBA{100, 100, 100, 255}))
tc.Add(Italic)
tc.Fprintf(&b, "hoge")
if e, g := "\x1b[48;2;255;0;0;38;2;100;100;... |
package main
import "matryoshka/core"
func main() {
matryoshka := core.NewMatryoshka()
matryoshka.Run()
} |
package paginationhelper
import (
"strconv"
)
const (
DefaultPage int = 1
DefaultLimit int = 10
)
// CalculatePageToOffset calculates offset based on page for query
/*
page = 1
limit = 10
offset = 0
page = 2
limit = 10
offset = (2-1) * 10 = 10
page = 2
limit = 2
offset = (2- 1) * 2 = 2
page = 2
limit = 3
offs... |
package logic
import (
"time"
)
/**
测试数据
*/
var (
ItemMap = make(map[uint]*Item)
)
func InitMap() {
now := time.Now()
item := &Item{
ID: 1,
Name: "电影票",
Total: 100,
Left: 100,
PlayTime: now.Add(time.Hour).Unix(),
Location: "cinema",
Image: "www.baidu.com",
BeginTime... |
// Copyright 2016 Bobby Powers. All rights reserved.
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type ServiceConfig struct {
SessionKey string
CookieName string
AuthDir string
}
func ReadConfig(path string) (*ServiceConfig, error) {
config := new(ServiceConfig)
_, err := toml.DecodeFile(pa... |
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
"github.com/valyala/tcplisten"
)
func main() {
app := iris.New()
app.Use(recover.New())
app.Use(logger.New())
// 输出html
// 请求方式:GET
// 访问地址:http://localhost:8080/welcome
... |
package gogo
import (
"log"
"os"
"path"
)
var (
// FindModeConfigFile returns config file for specified run mode.
// You could custom your own run mode config file by overwriting.
FindModeConfigFile = func(runMode, srcPath string) string {
// adjust srcPath
srcPath = path.Clean(srcPath)
filename := "appl... |
package handler
import (
"context"
"errors"
"fmt"
"github.com/jinmukeji/jiujiantang-services/service/auth"
corepb "github.com/jinmukeji/proto/v3/gen/micro/idl/partner/xima/core/v1"
subscriptionpb "github.com/jinmukeji/proto/v3/gen/micro/idl/partner/xima/subscription/v1"
jinmuidpb "github.com/jinmukeji/proto/v3... |
package main
import (
"fmt"
)
type Msg struct {
Dist int
Sender string
}
type Token struct {
Sender string
}
func main() {
ch := make(chan interface{}, 10)
ch <- Token{"P"}
ch <- Msg{10, "Q"}
ch <- Token{"R"}
for v := range ch {
switch t := v.(type) {
case Token:
fmt.Printf("Got a Token %s\n", t... |
/*
* Customers API
*
* Customers focuses on solving authentic identification of humans who are legally able to hold and transfer currency within the US. Primarily this project solves [Know Your Customer](https://en.wikipedia.org/wiki/Know_your_customer) (KYC), [Customer Identification Program](https://en.wikipedia.o... |
package main
import (
"fmt"
)
type teste int
var x teste
func main() {
fmt.Printf("tipo:%T\nvalor:%v\n", x, x)
x = 42
fmt.Printf("x:%d\n", x)
}
|
/* 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 list of conditions... |
package healthcheck
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestPingRoute(t *testing.T) {
router := prepareRouter()
recorder := performRequest(router,http.MethodGet, "/healthcheck")
response, err := readJson(r... |
package test
import listen "cdc"
var connParams = listen.DBConnParams{
Host: "postgres",
Port: 5432,
User: "postgres",
Pass: "password",
Name: "test",
}
|
package instance
import (
"context"
"fmt"
"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_instances"
"github.com/IBM-Cloud/power-go-client/power/client/p_... |
// Using make() function
/*
You can also create a slice using the make() function
which is provided by the go library. This function takes
three parameters, i.e, type, length, and capacity.
It assigns an underlying array with a size that is equal
to the given capacity and returns a slice which refers to the
... |
package hashobject
import (
"fmt"
"got/internal/got/filesystem"
"github.com/spf13/cobra"
)
var Cmd = &cobra.Command{
Use: "hash-object [-w] <file>...",
Short: "Compute object ID and optionally creates a blob from a file",
Args: cobra.ExactArgs(1),
}
func init() {
write := Cmd.Flags().BoolP("write", "w", ... |
// Copyright 2020 beego-dev
//
// 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 writin... |
package util
import "errors"
var (
ErrUrlRequired = errors.New("URL不能为空")
ErrNovelNotExistInMap = errors.New("哈希map中索引不到小说")
ErrInvalidVoteTypeNumber = errors.New("投票类型数量不正确")
)
|
package run_step_test
import (
"errors"
"time"
"github.com/cloudfoundry-incubator/executor/sequence"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cloudfoundry-incubator/garden/client/connection/fake_connection"
"github.com/cloudfoundry-incubator/garden/client/fake_warden_client"
"github... |
package netcode
import (
"fmt"
"net"
"inet.af/netaddr"
)
// ip types used in serialization of server addresses
const (
ADDRESS_NONE = iota
ADDRESS_IPV4
ADDRESS_IPV6
)
// This struct contains data that is shared in both public and private parts of the
// connect token.
type sharedTokenData struct {
TimeoutSec... |
package main
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"image"
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/tc-hib/winres"
"github.com/tc-hib/winres/version"
)
const (
errInvalidSet = "invalid resource set definition"
errInvalidCursor = "in... |
package main
import (
. "fmt"
. "runtime"
. "sync"
)
func increment(c chan int, wg *WaitGroup) {
for x := 0; x < 10; x++ {
a := <-c
a++
c <- a
}
defer wg.Done()
}
func decrement(c chan int, wg *WaitGroup) {
for x := 0; x < 11; x++ {
a := <-c
a--
c <- a
}
defer wg.Done()
}
func main() {
var wg ... |
package util
import (
"testing"
)
func TestFloor(t *testing.T) {
a := 10.46405786
b := 0.010000000
c := Floor(a, b)
if c != 10.46 {
t.Fatal("failed test")
}
}
|
/*
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
*/
package main
import (
"fmt"
"math/big"
"strconv"
"strings"
)
func main() {
n := big.NewInt(0)
two := big.NewInt(2)
exp := big.NewInt(1000)
n = n.Exp(two, exp, nil)
sum := 0
for _, ... |
package common
import (
"errors"
"path"
"github.com/connext-cs/pub/log"
"regexp"
"strings"
"github.com/astaxie/beego"
)
//ValidIPSegment ... 是否是正确的IP地址段格式 172.10.16.0/32
func ValidIPSegment(value string) error {
const MatchKey = `^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\... |
package serializers
import "persons.com/api/domain/person"
type PersonSerializer interface {
Decode(input []byte) (*person.Person, error)
Encode(input *person.Person) ([]byte, error)
EncodeMultiple(input []*person.Person) ([]byte, error)
}
|
// Copyright 2021 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 helm
import (
"io/ioutil"
"log"
"strings"
"github.com/loqutus/artifactory-replication/pkg/artifactory"
"github.com/loqutus/artifactory-replication/pkg/s3"
"github.com/loqutus/artifactory-replication/pkg/slack"
"k8s.io/helm/pkg/repo"
)
func RegenerateIndexYaml(artifactsList []string, artifactsListProd ... |
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"log"
"net/http"
"fmt"
)
func main() {
db,err:=sql.Open("mysql","root:password@tcp(127.0.0.1:3306)/test1")
if err!=nil{
log.Fatal(err)
}
defer db.Close()
err = db.Ping()
if err != nil {
log.Fatal(err)
}
http.HandleFunc("/",ind... |
// time: o(n), space: o(n)
/**
* Definition for a Node.
* type Node struct {
* Val int
* Left *Node
* Right *Node
* Next *Node
* }
*/
func connect(root *Node) *Node {
if root == nil {
return root
}
stack := []*Node{root}
next := (*Node)(nil)
for len(stack) > 0 {
... |
package _meta
// ParseCard returns the integer value of a card following blackjack ruleset.
func ParseCard(card string) int {
switch card {
case "ace":
return 11
case "two":
return 2
case "three":
return 3
case "four":
return 4
case "five":
return 5
case "six":
return 6
case "seven":
return 7
ca... |
package splash
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
neturl "net/url"
"strings"
"time"
"github.com/pquerna/cachecontrol/cacheobject"
"github.com/sirupsen/logrus"
"github.com/slotix/dataflowkit/errs"
"github.com/slotix/dataflowkit/logger"
"github.com/spf1... |
package main
import "fmt"
func main() {
var x uint8 = 1 << 1 | 1 << 5
for i := uint(1); i < 8; i++ {
if x&(1<<i) != 0 { // membership test
fmt.Println(i) // "1", "5"
}
}
}
|
package response
import (
"encoding/json"
"net/http"
"strconv"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
}
func New(code int, message string, data interface{}) *Response {
return &Response{code, message... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.