Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14171716
README.md
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
README.md
View Options
impart
======
 [](http://slack.write.as/)
**
impart
**
is
a
library
for
the
final
layer
between
the
API
and
the
consumer
.
It
'
s
used
in
the
latest
[
Write
.
as
](
https
:
//write.as) and [HTMLhouse](https://html.house) APIs.
We
'
re
still
in
the
early
stages
of
development
,
so
there
may
be
breaking
changes
.
##
Example
use
```
go
package
main
import
(
"fmt"
"github.com/writeas/impart"
"net/http"
)
type
handlerFunc
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
error
func
main
()
{
http
.
HandleFunc
(
"/"
,
handle
(
index
))
http
.
ListenAndServe
(
"127.0.0.1:8080"
,
nil
)
}
func
index
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
error
{
fmt
.
Fprintf
(
w
,
"Hello world!"
)
return
nil
}
func
handle
(
f
handlerFunc
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
handleError
(
w
,
r
,
func
()
error
{
// Do authentication...
// Handle the request
err
:=
f
(
w
,
r
)
// Log the request and result...
return
err
}())
}
}
func
handleError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
error
)
{
if
err
==
nil
{
return
}
if
err
,
ok
:=
err
.(
impart
.
HTTPError
);
ok
{
impart
.
WriteError
(
w
,
err
)
return
}
impart
.
WriteError
(
w
,
impart
.
HTTPError
{
http
.
StatusInternalServerError
,
"Internal server error :("
})
}
```
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 2:29 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3672212
Attached To
rI impart
Event Timeline
Log In to Comment