Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13825854
writeas.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
957 B
Subscribers
None
writeas.go
View Options
package
writeas
import
(
"errors"
"fmt"
"io/ioutil"
"net/http"
"time"
)
const
(
apiURL
=
"http://i.write.as"
)
type
API
struct
{
BaseURL
string
}
// defaultHTTPTimeout is the default http.Client timeout.
const
defaultHTTPTimeout
=
10
*
time
.
Second
var
httpClient
=
&
http
.
Client
{
Timeout
:
defaultHTTPTimeout
}
func
GetAPI
()
*
API
{
return
&
API
{
apiURL
}
}
func
(
a
API
)
Call
(
method
,
path
string
)
(
int
,
string
,
error
)
{
if
method
!=
"GET"
&&
method
!=
"HEAD"
{
return
0
,
""
,
errors
.
New
(
fmt
.
Sprintf
(
"Method %s not currently supported by library (only HEAD and GET).\n"
,
method
))
}
r
,
_
:=
http
.
NewRequest
(
method
,
fmt
.
Sprintf
(
"%s%s"
,
a
.
BaseURL
,
path
),
nil
)
r
.
Header
.
Add
(
"User-Agent"
,
"writeas-go v1"
)
resp
,
err
:=
httpClient
.
Do
(
r
)
if
err
!=
nil
{
return
0
,
""
,
err
}
defer
resp
.
Body
.
Close
()
content
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
resp
.
StatusCode
,
""
,
err
}
return
resp
.
StatusCode
,
string
(
content
),
nil
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Feb 18, 7:32 PM (9 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3631422
Attached To
rWGO writeas-go
Event Timeline
Log In to Comment