text
stringlengths
11
4.05M
// 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 intel import ( "context" "fmt" "time" "chromiumos/tast/errors" "chromiumos/tast/remote/firmware/fixture" "chromiumos/tast/remote/powercontrol" "chromiumos/ta...
package cmd import ( "fmt" "github.com/cnrancher/autok3s/cmd/common" "github.com/cnrancher/autok3s/pkg/providers" "github.com/cnrancher/autok3s/pkg/utils" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) var ( createCmd = &cobra.Command{ Use: "create", Short: "Create a K3s cluster", } cProvid...
package main import ( "errors" "os" "strconv" ) func getArgs() (accTXTFP, rssURL string, forumID int, err error) { args := os.Args[1:] if len(args) != 3 { err = errors.New("<acc.txt file path> <lenta.ru rss feed," + "for example http://lenta.ru/rss >" + " <forum id ie http://forum.sc2tv.ru/forums/{id}>...
package algorithm // Ketama Hash return 0 ~ (2^32 - 1) . // Inner uses lower letter if not unix_socket . // Distributed system does not use unix_socket . // Hash Value >= 0 , unsigned value // Try its best to defined Unsigned Value . // Each instance default weight is 1 (recommand), that must be >= 1 . import ( "cr...
package cache import ( "strconv" "time" ) func timeSlot(dur time.Duration) string { durSec := int64(dur / time.Second) if durSec <= 0 { return "" } slot := time.Now().Unix() / durSec return strconv.FormatInt(slot, 10) }
package maccount import ( "time" "webserver/common" "webserver/models" ) type UserAccount struct { Id int UserId int Amount float64 Freeze float64 Status int Extra string CreatedAt time.Time UpdatedAt time.Time } func FindUserAccountById(userId interface{}) (*UserAccount, error) { ...
// Copyright 2021 The ChromiumOS Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. package mgs import ( "chromiumos/tast/common/policy" "chromiumos/tast/local/chrome" ) // Option is a self-referential function can be used to configure MGS mode. // See h...
package v1 import ( "net/http" "net/http/httptest" "testing" "github.com/robert-inkpen/randeng_co_mirror/backend/config" ) func TestWebserver(t *testing.T) { cfg, err := config.Load() if err != nil { t.Error(err) } s := NewServer(cfg) t.Run("Test Prom Metrics Endpoint", func(t *testing.T) { w := httpte...
// Copyright 2018 Satoshi Konno. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build bsd freebsd darwin package transport import ( "os" "syscall" ) // SetReuseAddr sets a flag to SO_REUSEADDR and SO_REUSEPORT func (sock *Socket) Se...
package main import ( "fmt" ) func main() { if true && true { fmt.Println("0") } if !false && true { fmt.Println("1") } if !!true && !false { fmt.Println("3") } if true || false { fmt.Println("4") } if true || true { fmt.Println("5") } }
package k8swatch import ( "context" "fmt" "testing" "time" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/types" "github.com/tilt-dev/tilt/internal/controllers/apis/cluster" "github.com/tilt-dev/tilt/internal/controllers/fake" "github.com/tilt-dev/tilt/pkg/apis" "github.com/tilt-dev/tilt/pk...
package main import ( "sync" "github.com/singchia/go-hammer/doublinker" ) const ( AUTHORIZING = iota + 10 AUTHORIZED CHATTING OPERATING INTERACTING UNKNOW ) var singleSSI *sessionStatesIndex var mutexSSI sync.Mutex type handler interface { handle(chid doublinker.DoubID, cmd string, suffix string) delete(...
package main import ( "github.com/PROger4ever-Golang/Redis-serialization-benchmarks/utils" "github.com/jinzhu/configor" ) type Address struct { Host string `yaml:"Host"` Port int `yaml:"Port"` } type Config struct { CommonRedis Address `yaml:"CommonRedis" required:"true"` RejsonRedis Address `yaml:"RejsonRe...
package appkey import ( yaml "gopkg.in/yaml.v2" "github.com/joernweissenborn/aursir4go/util" ) type AppKey struct { ApplicationKeyName string Functions []Function } type Function struct { Name string Input []Data Output []Data } type Data struct { Name string Type int } func (AppKey *AppKey) Create...
package core import ( "io" "mime" "net/url" "os" "path/filepath" "github.com/jzaikovs/core/loggy" ) func init() { mime.AddExtensionType(".json", MIME_JSON) } // ServeFile this is just for development, file handling (CDN) better done by nginx or other // TODO: there can be better alternative just to use http....
package main import ( "github.com/gin-gonic/gin" "github.com/swaggo/files" // swagger embed files "github.com/swaggo/gin-swagger" // gin-swagger middleware _ "ingrid-coding-assignment/docs" "ingrid-coding-assignment/route" ) func initializeRoutes(router *gin.Engine) { // Swagger url := ginSwagger.URL("ht...
package main //457. 环形数组是否存在循环 //存在一个不含 0 的 环形 数组nums ,每个 nums[i] 都表示位于下标 i 的角色应该向前或向后移动的下标个数: // //如果 nums[i] 是正数,向前(下标递增方向)移动 |nums[i]| 步 //如果nums[i] 是负数,向后(下标递减方向)移动 |nums[i]| 步 //因为数组是 环形 的,所以可以假设从最后一个元素向前移动一步会到达第一个元素,而第一个元素向后移动一步会到达最后一个元素。 // //数组中的 循环 由长度为 k 的下标序列 seq 标识: // //遵循上述移动规则将导致一组重复下标序列 seq[0] -> seq[1...
package apilifecycle import godd "github.com/pagongamedev/go-dd" // ValidateParam Type type ValidateParam = func(context *godd.Context) (requestValidatedParam interface{}, goddErr *godd.Error) // ValidateParam Set func (api *APILifeCycle) ValidateParam(handler ValidateParam) { api.validateParam = handler } // GetV...
package models import ( "bytes" "encoding/json" "fmt" "os" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" "github.com/google/uuid" "github.com/qor/admin" "github.com...
// +build integration package main import ( "fmt" "os" "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/osbuild/osbuild-composer/internal/boot/azuretest" ) func panicErr(err error) { if err != nil { panic(err) } } func printErr(err error) { if err != nil { fmt.Println(err) } } // Generat...
package classifier import ( "encoding/json" "github.com/louistsaitszho/wggesuchtscraper/validator" ) // Output is the return type of the classifier. It contains all the meta data about the url you just enter. // TODO see if it is a good idea to make some enum-like things type Output struct { DataSrouce string Is...
package edGalaxy import ( "encoding/json" "fmt" "testing" ) type tStep struct { val int64 expected string } var ( tSteps = []tStep{ tStep{2, `[{"time_mark":2,"visit_count":1}]`}, tStep{4, `[{"time_mark":4,"visit_count":1},{"time_mark":2,"visit_count":1}]`}, ...
package volsupervisor import ( "github.com/contiv/volplugin/config" log "github.com/Sirupsen/logrus" ) type volumeDispatch struct { config *config.TopLevelConfig tenant string volumes map[string]*config.VolumeConfig } func iterateVolumes(config *config.TopLevelConfig, dispatch func(v *volumeDispatch)) { ten...
package view import ( caos_errs "github.com/caos/zitadel/internal/errors" org_model "github.com/caos/zitadel/internal/org/model" "github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/view/repository" "github.com/jinzhu/gorm" ) func OrgByID(db *gorm.DB, table, orgID string...
package config import "os" type Config struct { Host string Port string TZ string ENV string Image string Mongos []Mongo JWTSecret string } type Mongo struct { URI string ConnectionName string DatabaseName string } func New() *Config { config := &Config{} conf...
package common import ( "context" "fmt" "io/ioutil" "os" "path/filepath" "strings" "time" "github.com/google/go-github/github" "github.com/pkg/errors" ) const ( Monitoring_Owner = "pingcap" Monitoirng_Repo = "monitoring" Commit_Message = "Automatically generate monitoring configurations for %s" ) var...
package main import "fmt" // x 已声明 y 未声明 var x int func main() { //x, _ := f() x, _ = f() x, y := f() // 当多值赋值时,:= 左边的变量无论声明与否都可以 //x, y = f() fmt.Println(x, y) } func f() (int, int) { return 0, 1 }
// Copyright (C) 2019-2020 Zilliz. 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 l...
// Copyright 2019 The Cockroach Authors. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. // // As of the Change Date specified in that file, in accordance with // the Business Source License, use of this software will be governed // by the Apache License, ...
package main import ( "fmt" "sort" ) func main() { ints := []int{12, 4, 8, 54} // 排序 sort.Ints(ints) fmt.Printf("sort.Ints(ints) \n") if sort.IntsAreSorted(ints) { fmt.Printf("ints is sorted \n") for _, value := range ints { fmt.Printf("value: %d ", value) } // 搜索 x := 1 index := sort.SearchI...
package redisstore_test import ( "context" "log" "time" "github.com/opencensus-integrations/redigo/redis" "github.com/sethvargo/go-redisstore" ) func ExampleNew() { ctx := context.Background() store, err := redisstore.New(&redisstore.Config{ Tokens: 15, Interval: time.Minute, Dial: func() (redis.Conn...
package main import "fmt" type Contact struct { greeting string name string } func Greet(contact Contact) { myGreetingMas, myNameMas := CreateMessage(contact.name, contact.greeting, "howdy","Marcus") fmt.Print(myGreetingMas) fmt.Print(myNameMas) } // VARIADIC FUNCTIONS // a variable number of parameters o...
package main import ( "crypto/md5" "fmt" "io" "os" "log" "math/rand" "time" ) const ( dog="doge.jpg" cat="gcat.jpg" newCat="newGcat.jpg" newDog="newDoge.jpg" ) func alterHashit(filename string, alteredFilename string) ([]byte, []byte) { file, err := os.Open(filename) if err != nil { log...
package metadata import ( "bytes" "encoding/json" "errors" "net/http" "net/http/httptest" "testing" "github.com/edgexfoundry/edgex-go/internal/core/metadata/interfaces" "github.com/edgexfoundry/edgex-go/internal/core/metadata/interfaces/mocks" "github.com/edgexfoundry/edgex-go/internal/pkg/config" "github.c...
package main //import "fmt" type dHash struct { ht []hNode count int words []string } func dEnhash(s string, dh *dHash) int { i := enhash(s, len(dh.ht)) c := 0 k := doubleEnhash(len(dh.ht), s) for true { i = (i + c*k) % len(dh.ht) if dh.ht[i].key == "" { dh.ht[i].key = s dh.ht[i].count = 1 dh....
package main import ( "errors" "flag" "fmt" "log" "net/http" _ "net/http/pprof" "os" "path/filepath" "strconv" "strings" "bazil.org/fuse" "bazil.org/fuse/fs" "perot.me/splitfs/hashes" "perot.me/splitfs/split" ) var progName = filepath.Base(os.Args[0]) func usage() { fmt.Fprintf(os.Stderr, "Usage of %...
package client_test import ( "context" "testing" "time" "github.com/EventStore/EventStore-Client-Go/messages" "github.com/EventStore/EventStore-Client-Go/persistent" stream_revision "github.com/EventStore/EventStore-Client-Go/streamrevision" "github.com/stretchr/testify/require" ) func Test_PersistentSubscrip...
package users import ( gorm "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3" // _ "github.com/jinzhu/gorm/dialects/mssql" "errors" "golang.org/x/crypto/bcrypt" "strconv" "...
package game import "testing" func TestWhosNext(t *testing.T) { g := &Game{ MinSize, Players{'A', 'B', 'C'}, History{ Move{'A', 0, 0}, Move{'B', 1, 0}, Move{'C', 1, 1}, Move{'A', 0, 1}, }, } if p := g.WhoIsNext(); p != 'B' { t.Fatalf("false player: wanted B have %c", p) } }
package ipam import "context" type Interface interface { // Test executes the cluster IPAM test using the configured provider // implementation. The test processes the following steps to ensure the // provider specific operator implements guest cluster IPAM correctly. // // - Create guest clusters #1, #2, #3...
package types type StockProfileResp struct { Response Data struct { Sector Category `json:"sector"` Industry Category `json:"industry"` Company CompanyObject `json:"company"` //主要股东 Shareholder []ShareholderObject `json:"shareholder"` //股东更新时间 ShareholderUpdateAt int64 `json:"shareholderUp...
package onboarding import ( "encoding/json" "fmt" "math/rand" "net/http" "strconv" "time" "github.com/sirupsen/logrus" ) type InMemoryStore interface { SaveVerificationCode(code, email string) error GetVerificationCode(email string) (string, error) } type CodeStore map[string]string func (s CodeStore) Sav...
package exterrors import ( "encoding/json" "testing" ) func TestError_ErrDescription(t *testing.T) { const want = "test description" err := Error{ Description: want, } if got := err.ErrDescription(); got != want { t.Errorf("ErrDescription() = %v, want %v", got, want) } } func TestError_ErrField(t *testi...
// Copyright (c) 2016-2019 Uber Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
package container_test import ( "fmt" . "github.com/golangit/dic/container" "github.com/golangit/dic/definition" "github.com/golangit/dic/reference" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "reflect" "testing" "time" ) func TestDic(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Contain...
// 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 ...
// +build storage_badger storage_all !storage_pgx,!storage_boltdb,!storage_fs,!storage_sqlite package badger type logger struct { logFn loggerFn errFn loggerFn } func (l logger) Errorf(s string, p ...interface{}) { if l.errFn == nil { return } l.errFn(nil, s, p...) } func (l logger) Warningf(s string, p ...in...
package exchange import ( "github.com/stretchr/testify/assert" "log" "testing" ) func TestBitfinex_SetPairs(t *testing.T) { bitfinex := Bitfinex{} bitfinex.SetPairs() pairs := bitfinex.GetConfig().Pairs assert.Contains(t, pairs, &Pair{"ETH", "USD"}) assert.Contains(t, pairs, &Pair{"ETH", "BTC"}) } func Tes...
// Copyright 2019 Yunion // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writi...
// thanks dsal and Athiwat from #go-nuts for the amazing amount of help // and patience they showed package main import ( "fmt" "sync" ) func isPalindrome(n int) bool { n1, n2 := n, 0 for n != 0 { n2 *= 10 n2 += n % 10 n /= 10 } return n1 == n2 } func check(i, j int, c chan<- int) { k := i * j if isPal...
package main func main() { var x string x++ }
package main import ( "fmt" "strings" ) func dockerGetCgroupConfig() (string, error) { var dockerInfo = []string{"docker", "info"} stdout, _, err := execUserCmd(dockerInfo) if err != nil { return "", err } stdoutLines := strings.Split(stdout, "\n") for _, line := range stdoutLines { if strings.Contains(l...
package main type PublishMessage struct { // }
package core import ( "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/opspec-io/sdk-golang/pkg/model" "path" "path/filepath" ) var _ = Context("caller", func() { Context("newCaller", func() { It("should return caller", func() { /* arrange/act/assert */ Expect(newCaller(new(fakeC...
package main import ( "net/http" log "github.com/sirupsen/logrus" ) // twoHundred func twoHundred(w http.ResponseWriter, r *http.Request) { w.Header().Set("content-type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte(`{"message": "HTTP Endpoint OK!"}`)) } // fiveHundred func fiveHundred(w htt...
package main import "fmt" /* A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given an N x N grid of integers, how many 3 x 3 "magic square" subgrids are there? (Each subgrid is contiguous). Example 1: Input: [[4,3...
package v1 import ( "errors" "fmt" "net/url" "os" ) type Handler struct{} func NewHandler() *Handler { return &Handler{} } func (*Handler) Addr() (string, error) { port, ok := os.LookupEnv(envKeyPort) if !ok { return "", errors.New("PORT is not set") } return port, nil } func (*Handler) SessionKey() (s...
// Copyright 2018 The ChromiumOS Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Package caps is a package for capabilities used in autotest-capability. package caps import ( "context" "fmt" "regexp" "strings" "chromiumos/tast/autocaps" "chromi...
package balance import ( "testing" ) func TestAnalysis(t *testing.T) { type testData struct { q []rune a map[string]int } data := []testData{ testData{ []rune("C6H12O6"), map[string]int{"C": 6, "H": 12, "O": 6}, }, testData{ []rune("Fe2O3"), map[string]int{"Fe": 2, "O": 3}, }, testData{ ...
package main import "fmt" func main() { x := 1 y := 2 // apenas postfix x++ // x += 1 ou x = x +1 fmt.Println(x) y-- // y -= 1 ou y = y -1 fmt.Println(y) }
// Copyright 2018 The gVisor Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agree...
/* Copyright 2020 The Tilt Dev 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, sof...
package main import ( "fmt" "net" ) func main() { ln, err := net.Listen("tcp", ":8090") if err != nil { fmt.Println(err) } for { conn, err := ln.Accept() if err != nil { fmt.Println(err) } fmt.Println(conn) fmt.Println(&conn) } //go handleConnection(conn) }
package main import ( "os" "testing" ) func TestCreateDestinationFileStructure(t *testing.T) { config := GetTestConfig() config.Overwrite = true config.DestinationDirAbs = "./temp/testdestination/" err := CreateDestinationFileStructure(config) if err != nil { t.Errorf("Error creating the destination File S...
package main func main(a int) { }
package util import ( "encoding/base64" "testing" ) func TestECBDecrypt(t *testing.T) { key := []byte("04dc8389d85cb3093781ff6c6f994cd9") data := "1qXIZ5HeCS53vq6vekntsRBkPyaqd+c+282L+yNmCU6qBiLqnJyDFdwAeeM385TJ4KDD3p4EMJMdRnuU68I0tr2nO1h3NypEE0g+wxM4NKplol64MUCCX0En8OA1vRonQx1I6jV3OIXOazK2kZ7iMIc8o03YmHWKA7V5Q9X...
// Copyright 2020 Red Hat, Inc. and/or its affiliates // // 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 applic...
package main import ( "log" "time" "context" "fmt" "net/http" ) func main() { uri := "https://httpbin.org/delay/3" req, err := http.NewRequest("GET", uri, nil) if err != nil { fmt.Println(err) } ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond * 100) defer cancel() req = req....
package main import ( "encoding/json" "fmt" ) type Book struct { Name string `json:"name"` Page int `json:page` Price float32 `json:price` } func main() { book := Book{"go in actin", 345, 99.99} jsonStr, err := json.Marshal(book) if err != nil { fmt.Println("json marshal error", err) return } fm...
// Package openapi contains data structures for Swagger v2.0. // // We use these data structures to compare the API specification we // have here with the one of the server. package openapi // Schema is the schema of a specific parameter or // or the schema used by the response body type Schema struct { Properties ma...
/* * @lc app=leetcode.cn id=131 lang=golang * * [131] 分割回文串 * * https://leetcode-cn.com/problems/palindrome-partitioning/description/ * * algorithms * Medium (61.94%) * Total Accepted: 3.7K * Total Submissions: 6K * Testcase Example: '"aab"' * * 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。 * * 返回 s 所有可能的分割方案。 ...
package node_checker import ( "github.com/SkycoinPro/skywire-services-uptime/src/database/postgres" "time" "github.com/jinzhu/gorm" log "github.com/sirupsen/logrus" ) // store is node-checker related interface for dealing with database operations type store interface { findNodes() ([]Node, error) findNode(key...
package model type Ewei_shop_live_goods_option struct { Id int `orm:"id" json:"id"` Uniacid int `orm:"uniacid" json:"uniacid"` Goodsid int `orm:"goodsid" json:"goodsid"` Optionid int `orm:"optionid" json:"optionid"` Liveid int `orm:"liveid" json:"liveid"` Liveprice float64 `orm...