All Questions
467
questions
0
votes
3
answers
82
views
Can a Go interface receive any function, regardless of its signature?
EDIT: A couple of the answers have suggested changing the signature of the RegisterHandler function, however as part of the original question I asked if it were possible to further restict the types, ...
-3
votes
1
answer
71
views
How do interfaces in Go work when implementing functions with parameters/return values of a generalised type? [closed]
I'm new to Go and a bit confused in how interfaces work when implemented, especially wrt. functions that have parameters. Say I have an interface with function foo that takes in an interface:
type I ...
-1
votes
1
answer
82
views
Use more than one type package of multiple aws sdk services [duplicate]
I am using multiple services in my golang project and want to use the types package from more than one service. ie "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" & "...
5
votes
1
answer
134
views
Forward Declaration of Function Type in C
I want to declare a recursive function type (a function which declares itself) in C.
In a language like Go I can do:
type F func() F
func foo() F {
return foo
}
If I try to do the equivalent in C:
...
-3
votes
1
answer
50
views
How to multiple two values of type driver.Value [closed]
I have two variables, both are of type driver.Value, is there a way to multiply them?
This is a very primitive example:
var a driver.Value
var b driver.value
result := a*b
but getting an error like ...
1
vote
1
answer
46
views
Defining type as generic type instantiation
In the example below, I am trying to define a PreciseAdder type that would simplify the use of an instantiated generic type.
Unfortunately, the go compiler seems to think that the methods defined on ...
0
votes
1
answer
82
views
Is there a good way to make number type fit "method.Call" in golang?
Code Go Playground :
package main
import (
"fmt"
"reflect"
)
func (s StructWithManyMethods) Func1(a int, b uint, c float64) {
fmt.Printf("func:Func1 a:%d b:%d c:%...
-2
votes
1
answer
164
views
What's the difference between types.Implements and types.Satisfies?
What's the difference between types.Implements and types.Satisfies in golang?
I'm working on a code that inspects Go AST.
-1
votes
1
answer
196
views
Golang how to type json HTTP Response Body
I have a nested JSON object being sent in a request body, http protocol. One of the keys of the JSON field starts with an underscore '_'. How can I export the field? Example:
type TopologyGateway ...
1
vote
0
answers
131
views
Go YAML unmarshal to custom type - how to convert?
I am trying to unmarshal a YAML to a structure with multiple fields, some of them with custom types. One of those types is simply
type customType string
However, if I try to assign a string value, to ...
0
votes
1
answer
95
views
Go type constraint that describes mutable struct behavior
I would like to define a generic function where the type constraint describes mutable struct behavior.
What I mean by a "mutable behavior", is an interface like this:
type Unmarshaler ...
2
votes
0
answers
95
views
Golang record DB column changes
I have a DB table MyTable and a history record table HistoryRecord.
type MyTable struct {
MyInt int `gorm:"my_int"`
MyString string `gorm:"my_string"`
MyPolicy ...
2
votes
1
answer
2k
views
Golang: access a field on a generic of type `any` [duplicate]
I am working with a third-party function, with a generic of type any. That function returns an object of the type passed to it, and my own code works against that returned thing.
I'm trying to write ...
1
vote
1
answer
458
views
What's the correct way of returning one of different result values in one func in Golang?
I'm new to Go and was hoping to get some insights from more expirienced devs.
In my main function I call a 'Prepare' function that takes an enum as an argument. The enum is one of three options: A, B, ...
-2
votes
1
answer
74
views
How to convert a slice of derived type to slice of base type?
Say we have a base type and from it we derive another type
type baseType struct {
}
type derivedType struct {
baseType
}
How do I convert a slice of derivedType into baseType?
derivedTypeSlice := ...