Questions tagged [go]

18737 questions
1

votes
1

answer
31

Views

Can I recover elements that I sliced off the beginning of a slice?

a := []int{1,2,3,4,5,6} b := a[1:len(a)-1] fmt.Println(b) // -> [2 3 4 5] I can get the 6 back from b: c := b[:len(b)+1] fmt.Println(c) // -> [2 3 4 5 6] But can I get the 1 back? If I try c := b[-1:] I get invalid slice index -1 (index must be non-negative) If I can't get it back, does it mean it w...
AndreKR
1

votes
0

answer
37

Views

Weird issue in collision resolution of non-static bodies

I'm a bit of a beginner in engine development, so I decided to write my own engine from scratch so I could learn more about what happens under everything. I've been progressing fairly well, except the physics engine side of things have been giving me a bit of a headache. Here's a gif of what I mean:...
Felipe Rocha
1

votes
0

answer
54

Views

put and get json in ledger using go

I am quite new to Go programming. I am trying to insert a json into blockchain ledger and read it back using golang. My json looks like below: var jsonBytes = []byte(`[{'FLD1':10,'Fld2':'ABC'}, {'FLD1':100,'Fld2':'0.26'}]`) Ultimately, this json will be used as a look up table in my blockchain code....
user1456110
0

votes
0

answer
14

Views

Is this possible to assign other package struct in golang global variable and call dynamically?

File1.go file I added few struct with some attributes packageOne/File1.go package packageOne type exampleOne struct{ Id string Name string } type exampleTwo struct{ Street string State string } we can assign like this., File2.go created one struct and I assigned imported package struct's packageTwo...
nandakumar_r
0

votes
2

answer
26

Views

How to create a regex that will find a substring of a complex URL

Need some guidance on creating a regex that will identify part of the URL. URL1: test-project-233-TEST-ENDPOINT.test.as.ds.abcdefg.com URL2: test-project-124-ENDPOINT.test.dd.ad.gf.abcdefg.com The goal is to build a regex that can parse out 'test-project-233' and 'test-project-124' for me. I've alre...
Dyl
2

votes
0

answer
14

Views

Can Visual Studio debug Go plugins?

I have a Go project that consists of a command line tool and some Go plugins. I have a build script that builds the CLI, and then goes into a plugins directory and compiles each plugin with the -buildmode=plugin option. I would like to figure out if launch.json can be configured to selectively pas...
Nick Pollitt
1

votes
1

answer
796

Views

Golang SSH to Cisco Wireless Controller and Run Commands

I am trying to SSH to a Cisco wireless controller through Go, using Go's golang.org/x/crypto/ssh library, to programmatically configure access points. The problem I'm running into is correctly parsing the controller CLI in Go. For example, this is the typical SSH login to the controller: $ ssh (Cis...
mwalto7
1

votes
1

answer
203

Views

Echo is not clearing the session

I am using Echo for my web application. I tried to implement Login and Logout. When I tried to logout, its not clearing the session. Here is my code: func Logout(c echo.Context) error { sess, _ := session.Get('session', c) sess.Options = &sessions.Options{ Path: '/', MaxAge: -1, HttpOnly: tru...
pyprism
1

votes
1

answer
358

Views

How to deploy golang application on gcloud

Hi i am trying to deploy a golang application on gcloud using command on ubuntu:- gcloud app deploy app.yaml index.yaml But i am getting an error as follow:- ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed: /work_dir/github.com/stretch...
awsm sid
1

votes
0

answer
464

Views

Fatal error: runtime:out of memory during install of geth

# make geth build/env.sh go run build/ci.go install ./cmd/geth >>>/usr/lib/golang/bin/go install -ldflags -X main.gitCommit= -v github.com/ethereum/go-ethereum/dashboard # github.com/ethereum/go-ethereum/dashboard fatal error: runtime: out of memory runtime stack: util.go:45: exit status 2 exit s...
Jerry Hu
1

votes
0

answer
161

Views

What steps are required to migrated the gocd/go-server to a new system

I'm trying to move my gocd/go-server to a more powerful box. It's currently dockerized, but in short, i use a host volume, so i just rsync'd my whole project from system A to System B. Composer Service Entry: go-server: restart: unless-stopped image: gocd/gocd-server:v17.12.0 ports: - '8153:8153' -...
Jack Murphy
1

votes
0

answer
430

Views

Connect to a websocket - setup by socket.io - without socket.io

I'm trying to connect to wss://streamer.cryptocompare.com from cryptocompare.com, using the go gorilla lib. Is it just me, or isn't this possible? They're using socket.io as their backend.
Mobilpadde
1

votes
0

answer
217

Views

GO Datastore connection reuse

I am new to GO and i need to reuse the datastore client in the entire application instead of creating it again and again for each API call. I have created a db package and in it Init i am storing client in a global db variable to reuse it via a GetDB() function. But i am getting the below error Per...
Vishal Bisht
1

votes
1

answer
115

Views

How to verify JWT?

I'm unsure of the examples in Google's documentation. How do I verify a JWT produced by Firebase, in a Google App engine flexible service? main.go: // ... func main () { InitializeAppWithServiceAccount() go lib.GetStockData() http.HandleFunc('/_ah/someendPoint', SomeHandler) } func InitializeAppWith...
cbll
1

votes
1

answer
122

Views

Is there a libfaketime alternative for Golang?

I want to automate some tests where I have to manipulate the system time to check for authentication behaviours of a program that is written in golang. According to this post, libfaketime does not work with golang. Is there another way that I can achieve what I want to do with libfaketime? Here's a...
emma
1

votes
0

answer
394

Views

Using sqlx, to populated embedded structs from a table joined twice

My question in a nutshell: can I use sqlx's StructScan to populate two embedded structs with values sourced from the same SQL table joined twice? The help files to the useful sqlx package state this: A StructScan will set an id column result in Person.AutoIncr.ID, also accessible as Person.ID. To av...
Brent
1

votes
1

answer
203

Views

Upload file from Javascript Socket (Ps) to Golang API (Gin Gonic)

I am trying to upload a file to my server (Golang) from a photoshop script (javascript) Here is the service reading the file on the server: func Post(c *gin.Context) { // Read uploaded file file, header, err := c.Request.FormFile('file') if err != nil { c.JSON(utils.BuildError(err)) } if file == nil...
Adrien
1

votes
1

answer
218

Views

Using concurrency in nested for loop? (Brute force) [closed]

I'm adapting code from a C program I made in class & I'm trying to convert all the programs I've written in C into Go in order to learn the language. I'm not quite 'getting' concurrency yet though. How would I apply concurrency to a nested for loop? The current iteration of my program is SLOW, much...
Frank Jaeger
1

votes
0

answer
847

Views

Sending a signed transaction to deploy a contract (Ethereum)

My goal is to send a signed transaction to create a smart contract, however, I am facing an issue I have not been able to solve for few days: When I send the transaction (on a private chain), there are two different ending: - 1 Web3js tells me it worked, I can see the transaction on the block. Howe...
Andromelus
1

votes
0

answer
311

Views

Golang Json marshalling & unmarshalling [duplicate]

This question already has an answer here: Marshal returns empty json of my struct 1 answer How Do I Parse a JSON file into a struct with Go 1 answer JSON and dealing with unexported fields 2 answers json.Marshal(struct) returns “{}” 2 answers Golang Struct Won't Marshal to JSON [duplicate] 1...
D13
1

votes
1

answer
177

Views

How to disable debug logs (app and revel both) in app.conf file of revel framework?

I want to disable debug logs and want other logs to put in a file(logfile). I have tried following two snippets. But it doesnt work as expected. log.all.filter.module.app = logfile log.all.filter.module.revel = logfile log.debug.filter.module.app = off log.debug.filter.module.revel = off log.all.ou...
abhijit gupta
1

votes
1

answer
50

Views

Kindless ancestor query for different entity kinds in golang

According to the documentation, it should be possible to retrieve an ancestor and all of its descendants, regardless of their kind. In my implementation, I have a different kind of ancestor and descendant. The following codes however always returns the error 'invalid entity type': q := datastore.New...
fsapei
1

votes
0

answer
284

Views

Render template with inline js(golang/gin)

I am trying to render an html template context.HTML(http.StatusOK, 'my_html_template.html', information) where my_html_template.html has content My HTML page Please wait. Do not push back or refresh {{if eq .Action 'form'}} var form = '{{.PgData}}'; var elem=document.createElement('div'); elem.inne...
kartikmaji
1

votes
0

answer
618

Views

How to use the same vendor package a of a dependency in golang?

I have a project, say P, depends on a library L, which in turn depends on a vendor library V. Now P is also (directly) depends on V. Is it possible to tell the compiler just to use the V library in L/vendor ? Or else I must add V in P/vendor which i think is really redundant
jayven
1

votes
0

answer
71

Views

Golang db2cli running select query gets cgo error

I'm trying to use db2cli library (https://bitbucket.org/phiggins/db2cli/) to implement DB2 queries (select, insert, delete). But get CGO error when trying to run select queries. Here is my code: db, err := sql.Open('db2-cli', *connStr) if err != nil { return err } defer db.Close() rows, err := db.Qu...
Xiuwen Sun
1

votes
0

answer
326

Views

Static linking against external library

I'm trying to understand how to build static executable in Go and I need to link it against external library, in my case ORACLE, but the use case is generic. I do the following: go build -x --ldflags '-s -w -extldflags '-static -L$ORACLE_HOME/lib -lclntsh'' The compilation phase is fine, but linking...
Valentin
1

votes
0

answer
107

Views

how to close an IPv6 connection in golang

The code below is my tcpserver about accepting connections. After running a while, there're lots of established IPv6 connection left in the system. func (s *TCPServer) serve() { tcpaddr, err := net.ResolveTCPAddr('tcp', s.Addr) s.listener, err = net.ListenTCP('tcp', tcpaddr) for { conn, err := s.li...
Terry Pang
1

votes
0

answer
96

Views

How to mock a method that returns a struct?

Here's a little golang program that connects to localhost via ssh and does some sftp-like operations. It works fine but I would like to make the doTheWork() function more testable. I've read up on using gomock to create mocks for interfaces. So I've already created two interfaces, Sftper and Walker,...
Dan Tenenbaum
1

votes
1

answer
125

Views

How to add function to cron using Go reflect?

I am trying to schedule few jobs dynamically by reading configuration from file like below import ( 'github.com/robfig/cron' 'fmt' ) masterJobDetails :=// this is array of job from file c := cron.New() for k, v := range masterJobDetails { fmt.Println(k, v.JobName) c.AddFunc(v.CronExpression, v.JobN...
Gan
1

votes
0

answer
62

Views

Confusion about Go debug by GDB

I'm a java programer and I'm learning Go. Now I can use GDB simply and I have a doubt, when I debugging a Go program ,I can't check an object(or variable) what it exactly is. e.g. when I debug a java program,I can check everything in an object(or variable). public void catTest() { Cat cat1=new Cat('...
Ronacaodo
1

votes
0

answer
69

Views

Gorm and associations

I'm trying to figure out how to load associations with gorm. The documentation is not that great. I have to models: type Account struct { gorm.Model Name string `gorm:'column:name;unique_index;not null;size:255'` AccountTypeID uint `gorm:'not null'` UserID uint `gorm:'not null'`...
Tino
1

votes
0

answer
61

Views

Synchronize separate processes with using redis

I have four separate instances of a server running and I want only one of them to run a query every 5 seconds. The problem I am having is that they seem to be able to check the redis key that i have set for the last time the query was run so quickly that multiple instances run my query at the same t...
stihl
1

votes
0

answer
713

Views

gorm.DB can't preload field currencies for model.Currency

I was looking through gorm.DB's docs and sources but can't seem to understand the purpose of Preload. I thought that is the 'preloaded schema/tables/rows' that you can use afterwards' but cannot somehow use it that way. For instance I have the following struct package model type Currency struct { ID...
Patryk
1

votes
0

answer
549

Views

web3 connect to testnetwork

I try to connect with web3.php to a smart contract, published in the ropsten test network via metamask. I used the following web3.php library: (https://github.com/sc0Vu/web3.php). To create an rpc server, I used ethereum go and run the following commands: geth --testnet removedb geth --testnet --rpc...
HansPeterLoft
1

votes
0

answer
122

Views

Many to Many: Save and Update single struct not working

I'm trying to work with postgresql and gorm but I'm encountering the following problem. I have two structs (Tenantx,Userx) with a many2many relationship (this works) plus a field in each one (TenantAdmin,DefaultTenant) which relates to the other struct. Saving and Updating works with all fields exce...
Battalgazi
1

votes
1

answer
751

Views

missing Location in call to Time.In

When I ues beego/orm to operate postgresql database,there is an error like this 'missing Location in call to Time.In'. code example type dataTest struct { Id int `pk:'auto'` Data time.Time `orm:'auto_now;type(timestamp);null'` } local, _ := time.LoadLocation('UTC') test_time, err :...
fangtao
1

votes
1

answer
41

Views

how to implement a quoted printable decoder into reading the body of an email?

The following code (partial of the full code), creates a reader, then read the body of an email and store them into 'final body'. this final body is then passed into mongoldb for archiving. However, the message body that is read is quoted printable, and I want the body passed into mongodb to be deco...
Katherin Romanova
1

votes
1

answer
124

Views

mongodb update add each map structure's value

There is a map data {'a': 2, 'c': 4: 'd': 0}, and a document in MongoDB: { ... Score: { 'a': 1, 'b': 2, 'c': 0, } } The updated document: { ... Score: { 'a': 3, 'b': 2, 'c': 4, 'd': 0, } } Is what I wanted, now this works well: bson.M{'$inc': bson.M{'Score.a': 2,....}}, How can I use a map without k...
Sanghai
1

votes
0

answer
405

Views

Proxy protocol v2 for http and https in Go

I'm trying use AWS network ELB with proxy protocol (v2) to terminate the SSL on my server. I know that the ELB will inject the (binary) protocol information into the data stream at the beginning of the connection. I understand that I have to parse it and remove it from the stream. I'm trying to do t...
hamochi
1

votes
0

answer
52

Views

How to squash merge using git2go?

I'd like to perform 'git merge --squash' with git2go, such that I get one commit for the merge. That commit message could be all of the other commit messages listed together, but it would only be one commit. So far, I'm thinking I could rebase the branch to itself, squashing commits, and then merge?...
Bobby Battista

View additional questions