humboldtux
(Humboldtux)
September 4, 2016, 6:18pm
1
Hi,
I’d like to build a CLI for an API. I first want to implement the authentication process.
In curl, i first need to create a session token:
$ curl -X GET -H 'Content-Type: application/json' -H 'Authorization: user_token jlev3v39zgiplrgo1cvj3vvv9r13viqf45a61dezt' 'http://192.168.0.10/api/createSession' {"session_token":"bilkabrilblroj05lr3fe4dem2"}
Then i can use the token to resquest the API:
$ curl -X POST -H 'Content-Type: application/json' -H "Session-Token: bilkabrilblroj05lr3fe4dem2" http://192.168.0.10/api/getMyInfo {"4":{"name":"admin","role": "admin"}}
How do i do that in Go? Can you point me to clients source code that use a similar API?
Thank you.
radovskyb
(Benjamin Radovsky)
September 4, 2016, 6:24pm
2
Hey @humboldtux ,
If you want to convert curl to Go code, you should check out https://mholt.github.io/curl-to-go/ by @matt .
humboldtux
(Humboldtux)
September 4, 2016, 7:27pm
3
Thank you @radovskyb , that is a start, even if i’m more looking for a similar project on how to create the client, the session, handling request.
radovskyb
(Benjamin Radovsky)
September 5, 2016, 2:33am
4
Hey @humboldtux , if you give me a small walk down of the process you’re trying to implement, I or somebody else can help you find some resources to learn, or I can even just help you put something small together with some annotations to help you learn how it works if you’d like.
1 Like
geosoft1
(George Calianu)
September 5, 2016, 2:48pm
5
i guess that what you need is a golang http client (see net/http
package). an example is here .
1 Like
humboldtux
(Humboldtux)
September 11, 2016, 6:50pm
6
@geosoft , @radovskyb thank you for your help.
I didn’t find time to work on this. I will post as soon as i have something to show.
1 Like
system
(system)
Closed
December 10, 2016, 6:50pm
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.