Giter VIP home page Giter VIP logo

go-spvchannels's People

Contributors

ctnguyen avatar mergify[bot] avatar roppa avatar tigh-latte avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-spvchannels's Issues

Functional Options for Rest Client setup

Can you change the Client setups to use Functional Options instead of a config stuct. They are nicer to user and suers only need to set only what they need. I find option structs are confusing as you don't know if you need to set everything if you ony want to change 1 thing

func NewClient(c ClientConfig) *Client {

https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

Another example can be found https://github.com/tonicpow/go-paymail/blob/master/client.go#L19

A convention we're trying to use for these functions is With... so here we'd have WithInsecure, WithBaseURL etc. Setting any of these would update the default config.

Add close method to Socket client

At the moment there is a maxMessages variable to trigger when the socket run ends. I don't think this is overly user friendly, how would I know what to set this to and how would I gracefully shut down the socket if I need to exit early.

Instead we should add a Close method to the socket client. This can be called to shutdown and end the socket.

I'm not 100% familiar with the gorilla websocket, but the close method would need to shutdown the gorilla socket and end the run loop and clear our any processing messages. You may need to employ a notify channel to exit the Run loop, I have an example of this here https://github.com/libsv/bitcoin-hc/blob/master/transports/zmq/headers.go#L60

Doing this means the caller can control when the Run loop ends and removes the need to a user to know in advance how many messages they want to process.

Rename file

There's a file at the root called svchannels.go, should this be spvchannels.go?

Rename Id to ID

The linter will probably catch this, but adding in case it doesn't, rename all Acronyms in structs to be Uppercased, such as ID, JSON etc.

[FEATURE] Remove empty data structure

There are some endpoints that have empty reply, we actually use an empty struct to define them. It is recommended to not use them and does not return anything if the reply is empty by definition

Functional Options for Socket Client

Can you change the Client setups to use Functional Options instead of a config stuct. They are nicer to user and suers only need to set only what they need. I find option structs are confusing as you don't know if you need to set everything if you ony want to change 1 thing

func NewWSClient(c WSConfig, p ProcessMessage, m ...uint64) *WSClient {

https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

Another example can be found https://github.com/tonicpow/go-paymail/blob/master/client.go#L19

A convention we're trying to use for these functions is With... so here we'd have WithInsecure, WithBaseURL etc. Setting any of these would update the default config.

Fully document library with examples and verbose documentation

We have public comments on all methods but these could be improved with more detailed explanations and code examples, I find a handy tool to use when writing these is https://bradleyjkemp.dev/godoc-playground/ which lets you write and interact with go docs in real time.

A handy guide for writing godocs is https://elliotchance.medium.com/godoc-tips-tricks-cda6571549b and also https://go.dev/blog/godoc.

When this repo is published the docs will appear here https://pkg.go.dev/github.com/libsv/go-spvchannels so we want it to be as friendly to users as possible. Yep, we also need to update our other repos but lets make this one the example to follow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.