go

Why does go module ssh custom private repo (non-github) config still request https fetch?

柔情痞子 提交于 2021-01-29 15:35:00
问题 I am using Go modules. In order to use module version, I cannot use local module. For example: replace locakpkg => ../localpkg v0.1.0 The above will fail because replacement local path cannot have version so far (go 1.15). Thus, to make the module version work, I decided to use a private ssh repo. I did search how to make private ssh repo work for two days. By following many online articles, I did git config --global url.user@private.com:.insteadOf https://private.com/ go env -w GOPRIVATE

How to perform aggregations in Go using mongo-driver

拈花ヽ惹草 提交于 2021-01-29 13:54:11
问题 I have a MongoDB collection with 3 fields: _id: ObjectId field1: Number field2: Number I am doing this aggregation to get "distinct" field1/field2 rows and doing a total count of the results. This works OK in the client (Robo3t): db.mycollection.aggregate([ { $group: { _id: { field1: "$field1", field2: "$field2" }, } }, { $group: { _id: null, count: { $sum: 1 } } } ]) Result: { "_id" : null, "count" : 57.0 } How could I do this aggregation in Go using mongo-driver? There is this method to

How to preload child conditionally based on parent column?

时间秒杀一切 提交于 2021-01-29 13:28:45
问题 I'm able to preload all Guests related to Order using this syntax: Table(order). Preload("Guests"). Where("order.code = ?", orderCode). First(&order). Error Is it possible to to preload Guests based on a condition on a column in Order table? here is SQL for what I want to achieve: SELECT * FROM orders WHERE code = "xyz" SELECT * FROM guests WHERE (order_id IN (1)) AND (some_column_in_guest_tbl = some_column_in_order_tbl) Note: I'm aware of this Preload syntax (this doesn't take value from

(GoLANG) *sql.DB Scan rows into string array pointer

百般思念 提交于 2021-01-29 12:57:54
问题 I'm fairly new to handling sql databases through GO. I have an instance where I am scanning rows from my DB connection, into an slices of a nested struct in an instantiated slice. But can't seem to properly preform it. Is there some looping techniques or references that would be of some use in Golang. I have provided example code and can provide anything else. The connection pool is established and only when I go to scan the rows is where my program craps out. So my question is, if there are

Spread operator analogue

狂风中的少年 提交于 2021-01-29 12:49:36
问题 I have a struct and the instance of that struct: type Obj struct { ssid string code string mit string // and other props (23) } var ValidObject = Obj { ssid: "AK93-KADJ9-92J76", code: "SKO-120O" mit: "MSLA-923-OKSW" } I want to create a slice of structs ( Obj ) which will contain ValidObject with only some fields changed. I think the best way to explain that would be using pseudo code, so here it is (using spread operator from JS :) ): var slc = []Obj{ { ...ValidObject, code: "Other value", }

Go protobuf packages collision

末鹿安然 提交于 2021-01-29 12:44:13
问题 Hi I am trying to generate the simple protobuf file in Go language syntax = "proto3"; package gen; message EvtKeepAlive { string SvcName = 2; } In the header I see that the package uses two different proto go implementations, one from github.com and one from google.golang.org . As far as I understand the latter supersedes the former, so is this file generation valid? // versions: // protoc-gen-go v1.25.0-devel // protoc v3.13.0 // source: common.proto package gen import ( proto "github.com

Golang needs lock to read an int

為{幸葍}努か 提交于 2021-01-29 12:27:06
问题 In The Go Programming Language, Alan Donovan, page 264 he uses a mutex to read an int. I don't understand why since an int will fit in a single word, so it cannot be a torn read. I'm probably wrong, but how? Thanks. --- Update with code --- func Balance() int { mu.Lock() defer mu.Unlock() return balance } Then down the page func Withdraw(amount int) bool { Deposit(-amount) if Balance() < 0 { Deposit(amount) return false // insufficient funds } } This design lets the balance become invalid,

(GoLANG) *sql.DB Scan rows into string array pointer

别来无恙 提交于 2021-01-29 12:09:16
问题 I'm fairly new to handling sql databases through GO. I have an instance where I am scanning rows from my DB connection, into an slices of a nested struct in an instantiated slice. But can't seem to properly preform it. Is there some looping techniques or references that would be of some use in Golang. I have provided example code and can provide anything else. The connection pool is established and only when I go to scan the rows is where my program craps out. So my question is, if there are

golang xml Unmarshal

北慕城南 提交于 2021-01-29 11:33:46
问题 I am following the below example and trying to parse the xml and get day, date, high ,text, code. https://developer.yahoo.com/weather/#examples parsing Not working: <yahooWeather> <yweather:forecast day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30"/> </yahooWeather> parsing Working fine: <yahooWeather> <yweather day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30"/> </yahooWeather> trying to read/understand xml stadards and golang xml

Using two handlers for a GraphQL project; handle query with the second one if the first one is not capable of

江枫思渺然 提交于 2021-01-29 10:17:16
问题 I'm trying to use both SuperGraph as-a-library and GqlGen. So I have two handlers: the first one is SuperGraph ; this checks that it can carry out the operation the second one is GqlGen ; this checks that it can carry out the operation if the first one can't The code I'm using is this: type reqBody struct { Query string `json:"query"` } func Handler(sg *core.SuperGraph, next http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { bodyBytes, _ := ioutil.ReadAll(r