Interface vs Struct
See original GitHub issueThanks for this great library and your hardwork to make it great.
From https://pkg.go.dev/github.com/mxschmitt/playwright-go#pkg-index, the methods show out if the type is struct(like Playwright
):
type Playwright
func Run(options ...*RunOptions) (*Playwright, error)
func (c *Playwright) Dispose()
func (p *Playwright) Stop() error
But No method shows out if the type is defined as interface(like Page
), we need to go to the type definition to find the available methods.
type Page
Is it possible to define the Page
as struct?
type Page struct {
// non export fields
}
func (*Page) Click(selector string, options ...PageClickOptions) error
func (*Page) Fill(selector, text string, options ...FrameFillOptions) error
... ...
What do you think about it? Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Structs and Interfaces — An Introduction to Programming in Go
Like a struct an interface is created using the type keyword, followed by a name and the keyword interface . But instead of...
Read more >Exploring structs and interfaces in Go - LogRocket Blog
Go has struct types that contain fields of the same or different types. Structs are basically a collection of named fields that have...
Read more >Interfaces vs struct methods - Stack Overflow
When I use interface I have extra code in the form of interfaces declaration. If the interfaces perfectly implement polymorphism in Go, why...
Read more >Structs and interfaces - Getting Started with Go - CodinGame
Structs and Interfaces. We can use structs to group one of more fields of logical types together. For example we could represent a...
Read more >Struct and Interface in Go - Medium
We can think of struct as a wrapper of object. You can also check Golang spec (struct). ... We use Interface to group...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mxschmitt @AngangGuo I think use struct is better for both user and maintainer.
Actually, you can also generate code for structs, I don’t understand why only the interface can do that.
You can check this during the CI test process, pretty easy to use reflect to list all the methods of a struct. In this way, you can add more checks other than just check if a method is implemented, such as ensure unit test coverage, comments correctness.
I suggest checking the code design of Rod, it may help. Comparison with playwright: https://go-rod.github.io/#/why-rod?id=puppeteer
Thanks, maybe add detailed documents in the website later on.