go-interface Questions
9
Solved
I'm curious why Go does't implicitly convert []T to []interface{} when it will implicitly convert T to interface{}. Is there something non-trivial about this conversion that I'm missing?
Example:...
Tabling asked 5/10, 2012 at 20:48
3
Solved
If I understand Go practices correctly, callers (aka consumers) are supposed to define interfaces of what they want to use from their dependencies (aka producers).
However, if the producer has a fu...
Ampersand asked 4/10, 2022 at 22:33
4
Solved
Edit: This is not the right way to use interfaces in Go. The purpose of this question is for me to understand how empty interfaces work in Go.
If all types in Go implement interface{} (empty inter...
Mesomorphic asked 29/1, 2020 at 22:56
2
I'm not sure exactly how to phrase this question, and I've seen others ask similar but not really come up with answers (which tells me I'm asking the wrong question, but I'm not sure how else...
Undoing asked 14/10, 2021 at 9:24
1
Solved
I was trying to understand the Interface embedding with the following code.
I have the following:
type MyprojectV1alpha1Interface interface {
RESTClient() rest.Interface
SamplesGetter
}
// Sa...
Gustave asked 1/7, 2018 at 3:1
1
I have a variable, data, which is an interface. When I print its type, I get it as json.Number. How do I typecast to int/int64/float64?
If I try data.(float64), it ends up with a panic error:
pani...
Inobservance asked 25/1, 2018 at 12:59
3
I am newbie gopher and trying to get my head around the pointer receivers and interfaces.
type Foo interface {
foo()
}
type Bar struct {}
func (b *Bar) foo() {}
based on the above definitions....
Germanophile asked 12/8, 2017 at 16:32
3
Solved
EDIT++:
How to not to repeat my code in Go?
type Animal interface {
Kingdom() string
Phylum() string
Family() string
}
type Wolf struct {}
type Tiger struct {}
func (w Wolf) Kingdom() string {...
Aetna asked 25/10, 2016 at 14:3
2
Solved
I have the following code:
package main
import (
"log"
)
type Data struct {
Id int
Name string
}
type DataError struct {
Message string
ErrorCode string
}
func main() {
response := Data{...
Outstare asked 27/9, 2016 at 12:52
1
Solved
I have a slice of interface{} and I need to check whether this slice contains pointer field values.
Clarification example:
var str *string
s := "foo"
str = &s
var parms = []interface{}{"a",12...
Girosol asked 27/4, 2016 at 13:13
1
Solved
I've recently started studying Go and faced next issue. I want to implement Comparable interface. I have next code:
type Comparable interface {
compare(Comparable) int
}
type T struct {
va...
Metropolis asked 30/1, 2016 at 12:26
2
Solved
If I have the following interface and struct:
package shape
type Shape interface {
Area()
}
type Rectangle struct {
}
func (this *Rectangle) Area() {}
func New() Shape {
return &Rectangl...
Wavawave asked 27/10, 2013 at 6:37
5
Solved
I'm new to Go, and one of the first things I want to do is to port my little marked-up-page-generation library to Go. The primary implementation is in Ruby, and it is very much "classical object or...
Bacchic asked 13/7, 2012 at 8:49
1
© 2022 - 2024 — McMap. All rights reserved.