diff --git a/CONTRIBUTING.html b/CONTRIBUTING.html index a984a92..371c30d 100644 --- a/CONTRIBUTING.html +++ b/CONTRIBUTING.html @@ -17,6 +17,11 @@
+ + / +- Welcome to goSam, the easy-to-use http client for i2p. We're glad you're here - and interested in contributing. Here's some help getting started. + Welcome to goSam, the easy-to-use http client for i2p. We’re glad you’re here + and interested in contributing. Here’s some help getting started.
@@ -96,14 +95,11 @@ files.
- Tests are implemented using the standard go "testing" library in files named - "file_test.go," so tests of the client go in client_test.go, name lookups + Tests are implemented using the standard go “testing” library in files named + “file_test.go,” so tests of the client go in client_test.go, name lookups in naming_test.go, et cetera. Everything that can be tested, should be tested.
@@ -119,27 +115,21 @@ section below.
- If you discover the library doing something you don't think is right, please let + If you discover the library doing something you don’t think is right, please let us know! Just filing an issue here is OK.
- If you need to suggest a feature, we're happy to hear from you too. Filing an - issue will give us a place to discuss how it's implemented openly and publicly. + If you need to suggest a feature, we’re happy to hear from you too. Filing an + issue will give us a place to discuss how it’s implemented openly and publicly.
Please file an issue for your new code contributions in order to provide us with a place to discuss them for inclusion.
@@ -148,15 +138,12 @@ options.
First, add a variable to store the state of your new option. For example, the existing variables are in the Client class - + here:
@@ -165,21 +152,19 @@ steps. First, you create a functional argument in the options.go file, in the form: -// SetOPTION sets $OPTION - func SetOPTION(arg type) func(*Client) error { // arg type - return func(c *Client) error { // pass a client to the inner function and declare error return function - if arg == valid { // validate the argument - c.option = s // set the variable to the argument value - return nil // if option is set successfully return nil error - } - return fmt.Errorf("Invalid argument:" arg) // return a descriptive error if arg is invalid - } - } --
// SetOPTION sets $OPTION
+ func SetOPTION(arg type) func(*Client) error { // arg type
+ return func(c *Client) error { // pass a client to the inner function and declare error return function
+ if arg == valid { // validate the argument
+ c.option = s // set the variable to the argument value
+ return nil // if option is set successfully return nil error
+ }
+ return fmt.Errorf("Invalid argument:" arg) // return a descriptive error if arg is invalid
+ }
+ }
+
@@ -187,136 +172,116 @@
Next, you create a getter which prepares the option. Regardless of the type of
option that is set, these must return strings representing valid i2cp options.
- //return the OPTION as a string. - func (c *Client) option() string { - return fmt.Sprintf("i2cp.option=%d", c.option) - } --
//return the OPTION as a string.
+ func (c *Client) option() string {
+ return fmt.Sprintf("i2cp.option=%d", c.option)
+ }
+
- Lastly, you'll need to add it to the allOptions function and the + Lastly, you’ll need to add it to the allOptions function and the Client.NewClient() function. To add it to allOptions, it looks like this:
-//return all options as string ready for passing to sendcmd - func (c *Client) allOptions() string { - return c.inlength() + " " + - c.outlength() + " " + - ... //other options removed from example for brevity - c.option() - } --
//return all options as string ready for passing to sendcmd - func (c *Client) NewClient() (*Client, error) { - return NewClientFromOptions( - SetHost(c.host), - SetPort(c.port), - ... //other options removed from example for brevity - SetCompression(c.compression), - setlastaddr(c.lastaddr), - setid(c.id), - ) - } --
//return all options as string ready for passing to sendcmd
+ func (c *Client) allOptions() string {
+ return c.inlength() + " " +
+ c.outlength() + " " +
+ ... //other options removed from example for brevity
+ c.option()
+ }
+
+ //return all options as string ready for passing to sendcmd
+ func (c *Client) NewClient() (*Client, error) {
+ return NewClientFromOptions(
+ SetHost(c.host),
+ SetPort(c.port),
+ ... //other options removed from example for brevity
+ SetCompression(c.compression),
+ setlastaddr(c.lastaddr),
+ setid(c.id),
+ )
+ }
+
- Before the feature can be added, you'll need to add a test for it to + Before the feature can be added, you’ll need to add a test for it to options_test.go. To do this, just add your new option to the long TestOptions functions in options_test.go.
-func TestOptionHost(t *testing.T) { - client, err := NewClientFromOptions( - SetHost("127.0.0.1"), - SetPort("7656"), - ... //other options removed from example for brevity - SetCloseIdleTime(300001), - ) - if err != nil { - t.Fatalf("NewClientFromOptions() Error: %q\n", err) - } - if result, err := client.validCreate(); err != nil { - t.Fatalf(err.Error()) - } else { - t.Log(result) - } - client.CreateStreamSession("") - if err := client.Close(); err != nil { - t.Fatalf("client.Close() Error: %q\n", err) - } - } +-func TestOptionHost(t *testing.T) { + client, err := NewClientFromOptions( + SetHost("127.0.0.1"), + SetPort("7656"), + ... //other options removed from example for brevity + SetCloseIdleTime(300001), + ) + if err != nil { + t.Fatalf("NewClientFromOptions() Error: %q\n", err) + } + if result, err := client.validCreate(); err != nil { + t.Fatalf(err.Error()) + } else { + t.Log(result) + } + client.CreateStreamSession("") + if err := client.Close(); err != nil { + t.Fatalf("client.Close() Error: %q\n", err) + } + } - func TestOptionPortInt(t *testing.T) { - client, err := NewClientFromOptions( - SetHost("127.0.0.1"), - SetPortInt(7656), - ... //other options removed from example for brevity - SetUnpublished(true), - ) - if err != nil { - t.Fatalf("NewClientFromOptions() Error: %q\n", err) - } - if result, err := client.validCreate(); err != nil { - t.Fatalf(err.Error()) - } else { - t.Log(result) - } - client.CreateStreamSession("") - if err := client.Close(); err != nil { - t.Fatalf("client.Close() Error: %q\n", err) - } - } + func TestOptionPortInt(t *testing.T) { + client, err := NewClientFromOptions( + SetHost("127.0.0.1"), + SetPortInt(7656), + ... //other options removed from example for brevity + SetUnpublished(true), + ) + if err != nil { + t.Fatalf("NewClientFromOptions() Error: %q\n", err) + } + if result, err := client.validCreate(); err != nil { + t.Fatalf(err.Error()) + } else { + t.Log(result) + } + client.CreateStreamSession("") + if err := client.Close(); err != nil { + t.Fatalf("client.Close() Error: %q\n", err) + } + } -
If any of these tasks fail, then the test should fail.
- It's pretty simple to make sure the code style is right, just run gofmt over it + It’s pretty simple to make sure the code style is right, just run gofmt over it to adjust the indentation, and golint over it to ensure that your comments are of the correct form for the documentation generator.
- It may be useful to extend goSam in other ways. Since there's not a + It may be useful to extend goSam in other ways. Since there’s not a one-size-fits-all uniform way of dealing with these kinds of changes, open an issue for discussion and
@@ -326,10 +291,24 @@
This document was drawn from the examples given by Mozilla - + here
+