bogdanfinn / helheim-go

Go Wrapper for VeNoMouSNZ Helheim
10 stars 2 forks source link

client same as http.Client #2

Closed 1trackprojects1 closed 2 years ago

1trackprojects1 commented 2 years ago

It would be a lot better if the client was same as http.Client, which would save time when porting current code written with that to helheim.

bogdanfinn commented 2 years ago

@1trackprojects1 you can find here the full commit of a work in progress branch for this issue: https://github.com/bogdanfinn/helheim-go/commit/103a298172f190f7a9ff1e6b0cff64244a2e667c

the general idea is to have something like that in the end (error handling removed to keep example simple):

        helheimClient, _ := helheim_go.ProvideClient("YOUR_API_KEY", false, false, nil)

    log.Println("helheim client initiated")

    options := helheim_go.CreateSessionOptions{
        Browser: helheim_go.BrowserOptions{
            Browser:  "chrome",
            Mobile:   false,
            Platform: "windows",
        },
        Captcha: helheim_go.CaptchaOptions{
            Provider: "vanaheim",
        },
    }

    // up to this point everything is the same as before using this library

    helheimClientOptions := []helheim_go.HttpClientOption{
        helheim_go.WithWokou("chrome"),
        // add here other options like proxy, debug, or bifrost
        // helheim_go.WithDebug(),
        // helheim_go.WithBifrost("path/to/lib"),
        // helheim_go.WithProxyUrl("http://username:password@host:port"),
    }

        // here we create the httpClient. THIS is the client you use instead of net/http.Client
    httpCLient, _ := helheimClient.NewHttpClient(options, helheimClientOptions...)

    req, _ := http.NewRequest(http.MethodGet, "https://www.genx.co.nz/iuam/", nil)

        resp, _ := httpCLient.Do(req)

let me know what you think about the solution

1trackprojects1 commented 2 years ago

Yeah that sounds like a good idea, this way you can just swap out the client you were using to this one with some additional code above it.

bogdanfinn commented 2 years ago

https://github.com/bogdanfinn/helheim-go/releases/tag/v0.2.0