Go Forum
1,274 FOLLOWERS
This is a place for people who use the Go programming language or want to learn more about it. Here you'll find: Go questions and answers, discussions and announcements about Go packages and projects
Go Forum
18h ago
This function is to fetch some xml content and save it. One issue i encounterd is that how to send case s.updates ← pending[0]: (pending Item) one at a time. the code currently has an error of accessing index out of bound.
here’s the link to the full code : Better Go Playground
func(s *sub) loop(){
var pending []Item // appended by fetch; consumed by send
var next time.Time
var err error
var seen = make(map[string]bool) // set of item.GUIDS
for{
// var updates chan Item
var fetchDone chan fetchResult// if non-nil, fetch i ..read more
Go Forum
2d ago
Hello, I am new to Golang, and need to harden the built output ELF file to satisfy the required ELF security.
Specifically, for the source file hello.go:
// hello.go
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
Firstly, I built out a ELF file hello using command:
$ go build -build-mode=pie hello.go
Then I checked the ELF file via checksec tool:
$ checksec --file=hello
# --- output example ---
RELRO STACK CANARY NX PIE
No RELRO No canary found NX enabled PIE enabled
From the output of checksec, the RELRO and STACK CANARY ch ..read more
Go Forum
2d ago
There is no Operator Precedence Table for the Golang language in the help. Please I want a painting like this. Please Write all Operators in order of priority. Please list all Operators in order of priority. This is the deficiency.|
2 posts - 2 participants
Read full topic ..read more
Go Forum
2d ago
I am using a Go API to access my SQL tables. My tables all have created_at and updated_at fields, and I would like those fields to be controlled by SQL, not Go. So for example:
query, err := GetObjects[SomeSchema]("table_name") // calls table, then unmarshals into []SomeSchema
assert.Equal(query[0], SomeSchema{id: "whatever", created_at: /* some time object */, updated_at: ... })
What I would like is to define a simple way to ignore the created_at and updated_at fields in all such schema objects on marshal, so that they do not override the SQL values, but they are read in as normal on unmars ..read more
Go Forum
2d ago
This is first-time trying to experiment with code coverage for go-applications.
I am trying to play around with -cover flag to test code coverage but rest-endpoint.
I am referring this article: https://go.dev/doc/build-cover
Above example is working fine on machine - however I tried extending it to simple-rest api - it doesn’t seem to show 0% code coverage
This is smaller version prototype that I am trying to work.
I am seeing 0% code coverage even if the I am seeing the endpoint being hit, data getting retrieved
main.go
package main
import (
"encoding/json"
"log"
"ne ..read more
Go Forum
4d ago
I’m building a Go CLI application using Cobra and Viper libraries with numerous optional flags (10+). My primary goal is to execute actions only when their corresponding flags are specifically provided by the user.
I’ve tried follwoing approach: Utilizing cmd.Flags().StringVar(flagVar, flagName, defaultValue, usage) and cmd.Flag(“flagName”).Changed
Concerns:
Repetition of flag names.
Implicit binding between flagName and flagVariable.
I’ve explored an option to use viper.BindPFlag and viper.IsSet, but it hasn’t given an answer to any of my concerns, and it feels like overkill for this relati ..read more
Go Forum
1w ago
Hi,
My issue on github official repos was directly closed claiming that it is not a bug, that it is windows loader issue ??, i really didn’t understand the reason, so i would like to find some help here please, here is my issue: race tag: since go1.22 , running a program or running test with tag -race exit the program with status 0xc0000139 without any message for -v tag · Issue #66934 · golang/go · GitHub
1 post - 1 participant
Read full topic ..read more
Go Forum
1w ago
Thanks for helping me in advance. Fairly new to programming. I have two dependencies and some code first is puppy:
package puppy
func Bark() string{
return "Woof!"
}
func Barks() string {
return "Woof! Woof! Woof!"
}
github.com/dancoe77/008-puppy
Next would be dog:
import (
"strings"
)
func WhenGrownUp(s string) string {
return "When the puppy grows up it says: " + strings.ToUpper(s)
}
github.com/dancoe77/009-dog
Finally there is the code that joins the two:
package main
import(
"fmt"
"github.com/dancoe77/008-puppy"
"github.com/dancoe77/009-dog ..read more
Go Forum
1w ago
I’m new to Go and learning by translating a C++ program I have into Go.
The problem is that I have a graph with many types of nodes. In C++ this involves a base class and other classes built from that, along with coercing pointers to the base class into the correct node type.
My understanding is that I can do this in Go with interfaces and conversions. What I have so far (simplified) is
type Base struct{
id int
up int
}
type Node struct{
Base
left,right,down int
}
type Leaf struct{
Base
val string
}
//and this is just a huge guess that doesn't work
type NodeIf interface ..read more
Go Forum
1w ago
Hello ,
Sorry for such a simple question :
I am looking for a complex hello world example to illustrate a general module architecture and illustrate the maximum of situations :
4 packages , including packages at the same level and sub-packages
3 executables applications
appli_1.exe
appli_2.exe
appli_3.exe
The purpose of my question is to clearly understand the state of the art of import declaration in all the standard cases :
Q1) SUB_BRANCH ACCESS : import for accessing from Hello_from_a a function in sub_package_a_aa or sub_package_a_bb
Q2) EXTRA BRANCH ACCESS : import from sub_package_a_bb ..read more