question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interface vs Struct

See original GitHub issue

Thanks 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ysmoodcommented, Feb 1, 2021

@mxschmitt @AngangGuo I think use struct is better for both user and maintainer.

I can easily generate them and add documentation - as I do right now

Actually, you can also generate code for structs, I don’t understand why only the interface can do that.

I can ensure that I implement all upstream functions - the compiler ensures it

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

1reaction
AngangGuocommented, Jan 6, 2021

Thanks, maybe add detailed documents in the website later on.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found