text stringlengths 11 4.05M |
|---|
/*
Tencent is pleased to support the open source community by making Basic Service Configuration Platform available.
Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except
in compliance with the License. You may obtain... |
package service
import (
"context"
"net/url"
"github.com/ONSdigital/dp-api-clients-go/v2/health"
"github.com/ONSdigital/dp-net/v2/handlers/reverseproxy"
"github.com/ONSdigital/florence/assets"
"github.com/ONSdigital/florence/config"
"github.com/ONSdigital/florence/directors"
"github.com/ONSdigital/florence/se... |
package controllers
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/flux-web/flux-web/conf"
"github.com/flux-web/flux-web/models"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/httplib"
"github.com/a... |
package xmodule
import (
"log"
"time"
)
type module struct {
particle
}
// inject instance function struct
type particle struct {
pTime time.Time
}
// Insert particle
func (p *particle) Insert () (particle) {
p.pTime = time.Now()
return p
}
// remove particle
func (p *particle) Remove (pr particle) {
log.P... |
package main
import "fmt"
func main() {
//fmt.Println(circularGameLosers(5, 2))
//fmt.Println(circularGameLosers(4, 4))
fmt.Println(circularGameLosers(5, 3))
}
func circularGameLosers(n int, k int) []int {
j := 1
i := 1
mm := make(map[int]bool)
for {
if mm[i] {
break
}
mm[i] = true
i += k * j
... |
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"testing"
"time"
nats "github.com/nats-io/nats.go"
)
func TestNewJobOrder(t *testing.T) {
clientID := os.Getenv("CLIENT_ID")
natsServers := os.Getenv("NATS_SERVER_ADDR")
connector, err := Connect(clientID, natsServers)
ErrorIfNotNil(t, err, fmt.Sprin... |
package savior_test
import (
"io/ioutil"
"path/filepath"
"testing"
"github.com/itchio/wharf/wtest"
"github.com/itchio/savior"
"github.com/stretchr/testify/assert"
)
func Test_FolderSink(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir("", "foldersink-test")
wtest.Must(t, err)
fs := &sa... |
package public
import (
"github.com/tal-tech/go-zero/core/logx"
"net/http"
"tpay_backend/merchantapi/internal/common"
_func "tpay_backend/merchantapi/internal/handler/func"
"github.com/tal-tech/go-zero/rest/httpx"
logic_ "tpay_backend/merchantapi/internal/logic/public"
"tpay_backend/merchantapi/internal/svc"
)... |
package progressbar
import (
"fmt"
"time"
)
type DownloadBar struct {
octetsToDownload int64
octetsDownloaded int64
progressTheme ProgressTheme
previousRenderAt time.Time
previousDownloadOctetCount int64
downloadSpeedOctetsPerSecond int64
}
func NewDownloa... |
package client
import (
"context"
"github.com/openzipkin/zipkin-go"
zipkinhttpclient "github.com/openzipkin/zipkin-go/middleware/http"
"github.com/openzipkin/zipkin-go/model"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"io/ioutil"
"log"
"net/http"
"testing"
"time"
)
func TestClient_Ping(t *te... |
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
dummy := ListNode{0, nil}
curr := &dummy
carry := 0
for l1 != nil || l2 != nil {
var x, y int
if (l1 == nil) {
x ... |
// 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 server_request_handler
import "net"
import "log"
import "io"
import "encoding/json"
import . "../packet"
type ServerRequestHandler struct{
Listen net.Listener
Connection net.Conn
}
func (srh *ServerRequestHandler) NewSRH(protocol string, port string){
ln, _ := net.Listen(protocol, port)
conn, _ := l... |
// Copyright 2017 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... |
package data
import (
"testing"
)
func TestSession(t *testing.T) {
setupSession := func(t *testing.T) (session Session) {
t.Helper()
err := user.Create()
if err != nil {
t.Fatal(err)
}
gotUser, err := UserByUserIdStr(user.UserIdStr)
if err != nil {
t.Fatal(err)
}
session, err = gotUser.Create... |
//
// Copyright (c) 2016-2017, Arista Networks, Inc. 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 copyright notice,
// this ... |
package account
import (
"github.com/cbsinteractive/bitmovin-api-sdk-go/common"
"github.com/cbsinteractive/bitmovin-api-sdk-go/model"
)
type AccountLoginApi struct {
apiClient *common.ApiClient
}
func NewAccountLoginApi(configs ...func(*common.ApiClient)) (*AccountLoginApi, error) {
apiClient, err :... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//500. Keyboard Row
//Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like t... |
package main
import (
"fmt"
"time"
)
func fibonacci(mychan chan int) {
n := cap(mychan)
x, y := 1, 1
for i := 0; i < n; i++ {
mychan <- x
x, y = y, x+y
time.Sleep(time.Second)
}
// 记得 close 信道
// 不然主函数中遍历完并不会结束,而是会阻塞。
close(mychan)
}
func main() {
pipline := make(chan int, 50)
go fibonacci(pipline)... |
package main
import "fmt"
func main() {
if 2%2 == 1 {
fmt.Println("two is odd number")
} else {
fmt.Println("two is even number")
}
// ERRORS:-
// if{
// ###########
// } //else should be written along with "}" of previous "if"
// else{
// ################
// }
// ERRORS:-
// if 'sush' ... |
package leetcode
import (
"reflect"
"testing"
)
func TestShiftGrid(t *testing.T) {
if !reflect.DeepEqual(shiftGrid([][]int{
[]int{1, 2, 3},
[]int{4, 5, 6},
[]int{7, 8, 9},
}, 1),
[][]int{
[]int{9, 1, 2},
[]int{3, 4, 5},
[]int{6, 7, 8},
}) {
t.Fatal()
}
if !reflect.DeepEqual(shiftGrid([][]in... |
package model
import (
"config"
"constant"
"fmt"
"time"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
// mgo controller
type MgoDBCntlr struct {
sess *mgo.Session
db *mgo.Database
c *mgo.Collection
}
// DBNAME 数据库名字
var (
DBNAME = config.Conf.DB.DBName
globalSess *mgo.Session
mongoUR... |
package c
import (
"sync"
"testing"
)
func TestChannel(t *testing.T) {
wg := new(sync.WaitGroup)
queue := make(chan rune, 128)
worker := func(queue <-chan rune, resCh chan<- string) {
t.Log("on worker")
for {
str := <-queue
// do something
resCh <- string(str) + " [appended]"
}
}
general := func... |
package main
import (
"filesrv"
"imagesrv"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
// "github.com/jinzhu/gorm"
)
type App struct {
Router *mux.Router
// DB *gorm.DB
}
func main() {
a := App{}
serve(a)
}
func serve(a App) {
a.Router = mux.NewRouter().StrictSlash(true)
a.Init()
a.Ru... |
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/austindoeswork/NPC3/manager"
"github.com/austindoeswork/NPC3/server"
)
const (
port = ":80"
)
var (
versionFlag = flag.Bool("v", false, "git commit hash")
commithash string
)
func main() {
flag.Parse()
if *versionFlag {
fmt.Prin... |
package jsondiff
import (
"bytes"
"encoding/json"
"fmt"
"io"
"reflect"
"sort"
"gx/ipfs/QmRCUXvrfEEpWfqkLKqiaXE2uVaX73MGSVjLrfHDmzygTg/ansi"
)
// ResolutionType defines a type of comparison: equality, non-equality,
// new sub-diff and so on
type ResolutionType int
const (
TypeEquals ResolutionType = iota
Ty... |
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/user"
resty "gopkg.in/resty.v0"
)
var username = flag.String("username", "", "Username for onetimesecret.com, only needed the first time with -password")
var password = flag.String("password", "", "Password for onetim... |
// Copyright (C) 2019 The Android Open Source Project
//
// 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 exasol
import (
"context"
"crypto/rand"
"crypto/rsa"
"database/sql/driver"
"encoding/base64"
"encoding/hex"
"fmt"
"math/big"
"os/user"
"runtime"
"strconv"
"github.com/gorilla/websocket"
)
type connection struct {
config *config
websocket *websocket.Conn
ctx context.Context
isClosed ... |
package cli
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/evan-buss/openbooks/core"
"github.com/evan-buss/openbooks/irc"
)
func terminalMenu(irc *irc.Conn) {
fmt.Print("\ns)search\ng)et book\nd)one\n~> ")
// Trim user input so we don't send 2 messages
clean := func(message string) string { return strin... |
package bus
import (
"fmt"
"time"
"github.com/pkg/errors"
)
const (
CreateConnection = "CreateConnection"
UpdateConnection = "UpdateConnection"
DeleteConnection = "DeleteConnection"
CreateRelay = "CreateRelay"
UpdateRelay = "UpdateRelay"
DeleteRelay = "DeleteRelay"
StopRelay = "StopRelay"
ResumeRelay =... |
package list
/*import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
cloudpkg "github.com/devspace-cloud/devspace/pkg/devspace/cloud"
cloudconfig "github.com/devspace-cloud/devspace/pkg/devspace/cloud/config"
cloudlatest "github.co... |
package main
import "fmt"
type IF interface {
get() string
set(string)
}
type Doc struct {
text string
}
func (d Doc) get() string {
return d.text
}
func (d Doc) set(s string) {
d.text = s
}
|
package structs
import "time"
type Book struct {
ID int `json:"id"`
Title string `json:"title" binding:"required,min=2,max=200"`
Description string `json:"description"`
ISBN string `json:"isbn" binding:"required,min=8,max=10"`
Authors string `json:"authors" binding:"required,min=2,ma... |
package main
import (
"flag"
"fmt"
"github.com/macaron/go-mh-z19b"
)
func main() {
device := flag.String("device", "/dev/serial0", "specific MH-Z19B")
flag.Parse()
ppm, _ := mhz19b.Read(*device)
fmt.Printf("%d\n", ppm)
}
|
package main
import (
"fmt"
"runtime"
"runtime/debug"
"time"
)
func main() {
debug.FreeOSMemory()
var (
m1 runtime.MemStats
m2 runtime.MemStats
m3 runtime.MemStats
m4 runtime.MemStats
m5 runtime.MemStats
m6 runtime.MemStats
m7 runtime.MemStats
)
runtime.ReadMemStats(&m1)
t := struct{}{}
time.... |
// This file contains functions transpiling unary and binary operator
// expressions.
package transpiler
import (
"fmt"
"go/token"
goast "go/ast"
"github.com/elliotchance/c2go/ast"
"github.com/elliotchance/c2go/program"
"github.com/elliotchance/c2go/types"
"github.com/elliotchance/c2go/util"
)
func transpil... |
/*
Copyright 2021 The KubeVela 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, so... |
// Copyright 2016 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package syntax
import (
"testing"
"github.com/tanxiaolong/apidoc/types"
"github.com/issue9/assert"
)
// go1.9 BenchmarkDoc_Parse-4 50000 24044 ns/op
fun... |
package main
import (
"github.com/ActiveState/log"
"github.com/ActiveState/logyard-apps/sieve"
"github.com/ActiveState/stackato-go/server"
)
type Config struct {
Events map[string]map[string]sieve.EventParserSpec `json:"events"`
}
var c *server.Config
func getConfig() *Config {
return c.GetConfig().(*Config)
}... |
package API
import (
"Work_5/Service"
"Work_5/object"
"github.com/gin-gonic/gin"
"net/http"
)
func Comment(ctx *gin.Context) {
//绑定user,article,comment的参数
var user object.User
var article object.Article
var comment object.Comment
ctx.ShouldBind(&user)
ctx.ShouldBind(&article)
ctx.ShouldBind(&comment)
//... |
package main
import "fmt"
func main() {
bool
benar = true
bool
salah = false
if benar {
fmt.Println("benar", true)
}
}
|
package utils
// TODO this struct only exists because go sucks so hard it can not
// resolve cyclic dependencies. Therefore operations in the models
// package can not call anything from the database package (because
// database is also importing models, obviously).
// Why on gods green earth is go not being able to ... |
package datastore
import "fmt"
// DeleteAll deletes all records from a table.
func DeleteAll(table string) (err error) {
q := fmt.Sprintf("delete from %s", table)
_, err = Db.ExecContext(ctx, q)
if err != nil {
return
}
return
}
|
// Copyright (c) 2020 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package index
// import logpkg "github.com/echa/log"
//
// var log logpkg.Logger = logpkg.Log
//
// func init() {
// DisableLog()
// }
//
// func DisableLog() {
// log = logpkg.Disabled
// }
//
// func UseLogger(logger logpkg.Logger) {
// log... |
package main
type serveHttpTmplModel struct {
StructName string
Handlers []handlerTmplModel
}
type handlerTmplModel struct {
HandlerName string
ReceiverType string
URL string
Method string
IsProtected bool
}
type minMaxIntTmplModel struct {
FieldName string
MinValue string
MaxValue str... |
// Copyright 2018 Diego Bernardes. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package flare
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/go-kit/kit/log"
"github.com/pkg/errors"
document "github.com/diegobernarde... |
package main
import (
"encoding/json"
"flag"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
"github.com/Stratoscale/logserver/cache"
"github.com/Stratoscale/logserver/debug"
"github.com/Stratoscale/logserver/download"
"github.com/Stratoscale/logserver/dynamic"
"github.com/Strat... |
package main
import "fmt"
func main() {
var i [5]int = [5]int{1, 2, 3, 4, 5}
var slicedI []int = i[:]
fmt.Println(slicedI)
}
|
package sweetiebot
import "fmt"
import "time"
type Logger interface {
Log(args ...interface{})
LogError(msg string, err error)
Error(message string, channelID string)
}
type Log struct {
lasterr int64
info *GuildInfo
}
func (l *Log) Log(args ...interface{}) {
s := fmt.Sprint(args...)
fmt.Printf("[%s] %s\n... |
package peach
const (
//PeachDriverApollo
PeachDriverApollo = "apollo"
)
|
package redis_api
import (
// "os"
//"net/http"
)
var connections redisConnections
var handler *Message
func init() {
connections := make(redisConnections)
for _,conf := range RedisHosts {
hval := conf.GetHval()
connections[hval] = GetRedis(hval)
conn := connections[hval]
... |
package main
import (
"fmt"
)
func main() {
var t string = "我是测试字符串"
var r string
r = Reverse(t)
fmt.Println("我是测试字符串")
fmt.Println(r)
}
func Reverse(s string) string{
var str []rune = []rune(s)
fmt.Println(str)
for i, j := 0, len(str) -1; i < j; i ,j = i +1, j - 1 {
str[i], str[j] = str[j], str[i]
}
fm... |
/*
Copyright 2020 Gravitational, 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, soft... |
package main
import "fmt"
type ListNode struct {
Val int
Next *ListNode
}
func main() {
head := ListNode{4, &ListNode{5, &ListNode{6, &ListNode{7, nil}}}}
//printList(&head)
printList(rotateRight(&head, 8))
}
func printList(l *ListNode) {
for l != nil {
fmt.Printf("%+v %p\n", l, l)
l = l.Next
}
}
func ... |
package table_column
import (
tableColumn "yj-app/app/model/tool/table_column"
"yj-app/app/yjgframe/utils/convert"
)
//新增业务字段
func Insert(entity *tableColumn.Entity) (int64, error) {
_, err := entity.Insert()
if err != nil {
return 0, err
}
return entity.ColumnId, err
}
//修改业务字段
func Update(entity *tableColu... |
package producer
import (
"reflect"
"testing"
)
func getFieldString(obj interface{}, field string) string {
v := reflect.Indirect(reflect.ValueOf(obj))
return v.FieldByNameFunc(func(n string) bool {
return n == field
}).String()
}
func TestWithUnitName(t *testing.T) {
opt := defaultProducerOptions()
unitNam... |
package operators
import (
"context"
"reflect"
"github.com/go-logr/logr"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-ru... |
package main
import "fmt"
func abs(a int) int {
if a > 0 {
return a
}
return -a
}
func findDisappearedNumbers(nums []int) []int {
var ret []int
for _, v := range nums {
if nums[abs(v)-1] >= 0 {
nums[abs(v)-1] = -nums[abs(v)-1]
}
}
for i, v := range num... |
/*
Copyright 2017 Eliott Teissonniere
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,
publish, distribute,... |
package main
import "fmt"
func main() {
arrayDeclaration()
//arrayisValueType()
//arrayIteration()
//arraySlicing()
//variadicArrays()
//arrayBoundCheck([5]int{1, 2, 3, 4, 5}, 4)
//multiDimensionArray()
}
func arrayDeclaration() {
var x [5]int // An array of 5 integers with var declarationn
x[0] = 100
x[1]... |
package 排列组合问题
// 回溯 + 外部变量 实现全排列
var permuteSequence [][]int
func permuteUnique(nums []int) [][]int {
permuteSequence = make([][]int, 0)
permuteUniqueExec(nums, 0, len(nums)-1)
return permuteSequence
}
func permuteUniqueExec(nums []int, l int, r int) {
if l == r {
// 一定要加入深拷贝nums,否则之后对nums的修改会影响permuteSequence... |
package ionic
import (
"bytes"
"encoding/json"
"fmt"
"net/url"
"strings"
"github.com/ion-channel/ionic/pagination"
"github.com/ion-channel/ionic/teams"
)
// CreateTeamOptions represents all the values that can be provided for a team
// at the time of creation
type CreateTeamOptions struct {
Name s... |
/**
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agree... |
package _const
const (
PageNo = 1
PerPageLimit = 10
)
|
// +build ignore
// Package main demonstrates the use of `xflag` and `xflag/cflag`.
package main
import (
"flag"
"log"
"github.com/goaltools/xflag"
"github.com/goaltools/xflag/cflag"
)
var (
name = flag.String("name", "John Doe", "Name of the user.")
age = flag.Int("age", 16, "Age of the user.")
path = fla... |
package main
import "fmt"
func main(){
fah := 0.0
fmt.Println("Enter the degree in fahrenheit")
fmt.Scanf("%f",&fah)
Celsius := (fah - 32) * 5/9
fmt.Printf("The degree in Celsius is %f \n",Celsius)
}
|
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"os/signal"
"time"
)
const (
version string = "1.0"
)
var (
n = flag.Int("n", 5, "Specify an interval n seconds to run command")
h = flag.Bool("h", false, "Display Help")
v = flag.Bool("v", false, "Display version")
)
func main() {
flag.Parse()
if *v {
... |
// Test OneDrive filesystem interface
package onedrive_test
import (
"testing"
"github.com/ncw/rclone/backend/onedrive"
"github.com/ncw/rclone/fstest/fstests"
)
// TestIntegration runs integration tests against the remote
func TestIntegration(t *testing.T) {
fstests.Run(t, &fstests.Opt{
RemoteName: "TestOneDri... |
package db
import (
"errors"
"sync"
"github.com/gin-gonic/gin"
"urlshortener.api/models"
)
// Ensure MemoryDB conforms to DataAccessLayer interface.
var _ DataAccessLayer = &MemoryDB{}
// MemoryDB is a simple in-memory persistence layer for urlshortens.
type MemoryDB struct {
mu sync.Mutex
urlshorte... |
package shellcode
import (
"bytes"
"testing"
)
func TestX8664MemFdExec(t *testing.T) {
payload := `
#/bin/bash
echo "Hello from memfd_create exec sploit shellcode" > ./success.txt
`
x8664 := NewX8664()
shellcode, err := x8664.LinuxMemFdExec([]byte(payload))
if err != nil {
t.Fatal(err)
}
if len(shellcode... |
package authz
import (
"encoding/json"
"io"
"strconv"
"time"
"github.com/AuthzMemory/core"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/pkg/authorization"
// "fmt"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"golang.org... |
package main
import (
"os"
"path/filepath"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/widgets"
_ "github.com/therecipe/qt/internal/examples/showcases/wallet/assets"
_ "github.com/therecipe/qt/internal/examples/showcases/wallet/dashboard"
_ "github.co... |
package server
import (
"log"
"strconv"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo"
"github.com/AskJag07/virtuoso-server/config"
"github.com/AskJag07/virtuoso-server/controllers"
"github.com/AskJag07/virtuoso-server/middleware"
)
func NewRouter(client *mongo.Client) *gin.Engine {
Product... |
package actuator
import "logging"
type Curve interface {
Lookup(int) int
MapY(int, int, int, int) Curve
}
/*
* Linear interpolation between a min and a max. Should work well for
* everything
*/
type ClampedLinearCurve struct {
x1, y1, x2, y2 int
}
func ClampedLinear(x1, y1, x2, y2 int) Curve {
if x1>=x2 {... |
// 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 resp
type StatusesPublicLineRsp struct {
Statuses []struct {
CreatedAt string `json:"created_at"`
ID int64 `json:"id"`
Text string `json:"text"`
Favorited bool `json:"favorited"`
Truncated bool `jso... |
package lib
import "fmt"
func Log(sign, addr, msg string) string {
if addr == "" {
return fmt.Sprintf("[类型 : %v 操作: %v] ", sign, msg)
}
return fmt.Sprintf("[类型 : %v 用户: %v 操作: %v] ", sign, addr, msg)
}
func Loger(sign, msg string) string {
return fmt.Sprintf("[类型 : %v 操作: %v] ", sign, msg)
}
|
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"testing"
)
func TestOpenLogFile(t *testing.T) {
// test file open failure
f, lerr := OpenLogFile("")
if f != nil {
t.Error("shouldn't open an empty filename")
}
if lerr.Tag != "open-log-file" {
t.Errorf("invalid error tag %q", lerr... |
package frame
func newFloatBottomPolicy(frame *Frame) *floatBottomPolicy {
return &floatBottomPolicy{
Frame: frame,
}
}
// proactive action!
// note: most frame objects don't exist, make changes based on the frame config
func (policy *floatBottomPolicy) onInit() {
height := policy.Frame.config.Lines
if policy.F... |
package main
import "fmt"
func main() {
fmt.Println("hello world")
// printSomething()
}
// for loops
// func printSomething() {
// for i := 0; i < 10; i++ {
// fmt.Printf("this is number %d\n", i)
// }
// }
// go built in data types
// ** numbers like 32, 64, etc. represent bits
// integer types: uint8, ui... |
/*
Example:
package main
import (
"context"
"fmt"
"time"
"github.com/5xxxx/pie"
)
func main() {
t, err := pie.NewClient("demo")
t.SetURI("mongodb://127.0.0.1:27017")
if err != nil {
panic(err)
}
err = t.Connect(context.Background())
if err != nil {
panic(err)
}
var user User
err = t.filter("nic... |
package main
import "testing"
func TestPermutation(t *testing.T) {
var tests = []struct {
str1 string
str2 string
output bool
}{
{"the quick brown fox", "het uqkic wborn ofx", true},
{"ぁあぃぎじ", "じぎぃあぁ", true},
{"()[]", "][)(!", false},
{"ぁあぃぎじ", "じぎぃあぁ!", false},
}
for _, test := range tests {
... |
// +build unit
package http
import (
"bytes"
"errors"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io/ioutil"
"kz.nitec.digidocs.pcr/internal/models"
"kz.nitec.digidocs.pcr/internal/service"
"net/http"
"net/http/httptest"
"testing"
)
func TestPong(t *... |
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"text/tabwriter"
)
func main() {
raw, errRead := ioutil.ReadFile("messages.json")
if errRead != nil {
panic(errRead)
}
var skypeExport SkypeExport
if errUm := json.Unmarshal(raw, &skypeExport); errUm != nil {
panic(errUm)
}
fmt... |
//go:build release
package main
func init() {
globals.ReleaseMode = ReleaseModeRelease
}
|
package glsa
import (
"glsamaker/pkg/app/handler/authentication"
"glsamaker/pkg/app/handler/authentication/utils"
"glsamaker/pkg/database/connection"
"glsamaker/pkg/logger"
"glsamaker/pkg/models"
"glsamaker/pkg/models/bugzilla"
"net/http"
"strconv"
)
// Show renders a template to show the landing page of the ... |
package api
import (
"fmt"
"github.com/yaziedda/iser/app/common"
"github.com/yaziedda/iser/app/penawaran"
"log"
"net/http"
)
func GetPenawaranDataList(w http.ResponseWriter, r *http.Request) {
data := penawaran.GetListPenawaran()
log.Printf("%s%s", "Get list penawaran : ", data)
fmt.Fprintf(w, "%v", data)
}
... |
package router
import (
"net/http"
"os"
"path/filepath"
"github.com/abhinavnair/budget/internal/pkg/handler"
"github.com/go-chi/chi"
)
var (
wd string
)
func init() {
var err error
if wd, err = os.Getwd(); err != nil {
panic(err.Error())
}
}
// Handler returns the http handler that handles all the reque... |
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
"github.com/dobegor/calc"
)
var terms []*Term
func registerTerm(t *Term) {
terms = append(terms, t)
}
func parseTerms() {
for _, t := range terms {
t.Parse()
}
}
type Formula struct {
Fml string
Deps []*Term
f func(map[string... |
// Copyright (C) 2019 Cisco Systems 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 reda
import (
"encoding/xml"
"github.com/thought-machine/finance-messaging/iso20022"
)
type Document00100102 struct {
XMLName xml.Name `xml:"urn:iso:std:iso:20022:tech:xsd:reda.001.001.02 Document"`
Message *PriceReportV02 `xml:"reda.001.001.02"`
}
func (d *Document00100102) AddMessage() *PriceRe... |
package dao
import "github.com/darkarchana/darkarchana-backend/model"
// HeroesDao : Interface for Heroes DAO
type HeroesDao interface {
FindOne(model.DbOperate) (model.Heroes, error)
FindAll(model.DbOperate) ([]model.Heroes, error)
}
|
// 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 shipping_details
import (
shippingDetails "Pinjem/businesses/shipping_details"
"context"
"gorm.io/gorm"
)
type ShippingDetailRepository struct {
Conn *gorm.DB
}
func NewShippingDetailRepository(conn *gorm.DB) shippingDetails.DomainRepository {
return &ShippingDetailRepository{Conn: conn}
}
func (b *Sh... |
package db
import (
"fmt"
"github.com/jinzhu/gorm"
"github.com/spf13/viper"
_ "gorm.io/driver/mysql"
)
var Client *gorm.DB
type config struct {
host string
port string
user string
dbname string
password string
sslMode string
}
func Connect() error {
var err error
c := loadConfig()
dsn :=... |
package dandler
import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCanonicalHost(t *testing.T) {
testdata := []struct {
options int
url string
expectedStatus int
expectedHost string
expectedPort st... |
package router
import (
"bankBigData/_public/app"
"gitee.com/johng/gf/g/net/ghttp"
)
func Index(r *ghttp.Request) {
r.Response.WriteJson(app.Response{
Data: "API running",
Status: app.Status{
Code: 0,
Error: true,
Msg: "URL参数不正确",
},
})
}
func Status_500(r *ghttp.Request) {
r.Response.WriteJs... |
package helpers
import (
"newproject/env"
"time"
"github.com/dgrijalva/jwt-go"
)
//Claims defines bse claims
type Claims struct {
Username string `json:"username"`
jwt.StandardClaims
}
// ObtainToken generates new token for user
func ObtainToken(username string) (string, error) {
appKey := env.GetVariable("AP... |
package midtrans
import (
"crypto/sha512"
"fmt"
"io"
"time"
"github.com/imrenagi/go-payment"
)
// TransactionStatus is object used to store notification from midtrans
type TransactionStatus struct {
ID uint64 `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.