Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
github.com/takama/router
A simple, compact and fast router package to process HTTP requests. It has some sugar from framework however still lightweight. The router package is useful to prepare a RESTful API for Go services. It has JSON output, which bind automatically for relevant type of data. The router has timer feature to display duration of request handling in the header
package main
import (
"github.com/takama/router"
)
func Hello(c *router.Control) {
c.Body("Hello world")
}
func main() {
r := router.New()
r.GET("/hello", Hello)
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i http://localhost:8888/hello/
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Sun, 17 Aug 2014 13:25:50 GMT
Content-Length: 11
Hello world
package main
import (
"github.com/takama/router"
)
func main() {
r := router.New()
r.GET("/hello/:name", func(c *router.Control) {
c.Body("Hello " + c.Get(":name"))
})
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i http://localhost:8888/hello/John
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Sun, 17 Aug 2014 13:25:55 GMT
Content-Length: 10
Hello John
package main
import (
"github.com/takama/router"
)
// Data is helper to construct JSON
type Data map[string]interface{}
func main() {
r := router.New()
r.GET("/api/v1/settings/database/:db", func(c *router.Control) {
data := Data{
"Database settings": Data{
"database": c.Get(":db"),
"host": "localhost",
"port": "3306",
},
}
c.Code(200).Body(data)
})
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i http://localhost:8888/api/v1/settings/database/testdb
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 17 Aug 2014 13:25:58 GMT
Content-Length: 102
{
"Database settings": {
"database": "testdb",
"host": "localhost",
"port": "3306"
}
}
package main
import (
"github.com/takama/router"
)
// Data is helper to construct JSON
type Data map[string]interface{}
func main() {
r := router.New()
r.GET("/api/v1/settings/database/:db", func(c *router.Control) {
c.UseTimer()
// Do something
data := Data{
"Database settings": Data{
"database": c.Get(":db"),
"host": "localhost",
"port": "3306",
},
}
c.Code(200).Body(data)
})
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i http://localhost:8888/api/v1/settings/database/testdb
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 17 Aug 2014 13:26:05 GMT
Content-Length: 143
{
"duration": 5356123
"took": "5.356ms",
"data": {
"Database settings": {
"database": "testdb",
"host": "localhost",
"port": "3306"
}
}
}
package main
import (
"github.com/takama/router"
)
// Data is helper to construct JSON
type Data map[string]interface{}
func baseHandler(handle router.Handle) router.Handle {
return func(c *router.Control) {
c.CompactJSON(true)
if origin := c.Request.Header.Get("Origin"); origin != "" {
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
}
handle(c)
}
}
func Info(c *router.Control) {
data := Data{
"debug": true,
"error": false,
}
c.Body(data)
}
func main() {
r := router.New()
r.CustomHandler = baseHandler
r.GET("/info", Info)
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i -H 'Origin: http://foo.com' http://localhost:8888/info/
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://foo.com
Content-Type: text/plain
Date: Sun, 17 Aug 2014 13:27:10 GMT
Content-Length: 28
{"debug":true,"error":false}
https://google.github.io/styleguide/jsoncstyleguide.xml
:package main
import (
"net/http"
"github.com/takama/router"
)
func main() {
r := router.New()
r.GET("/api/v1/people/:action/:id", func(c *router.Control) {
// Do something
c.Method("people." + c.Get(":action"))
c.SetParams(map[string]string{"userId": c.Get(":id")})
c.SetError(http.StatusNotFound, "UserId not found")
c.AddError(router.Error{Message: "Group or User not found"})
c.Code(http.StatusNotFound).Body(nil)
})
// Listen and serve on 0.0.0.0:8888
r.Listen(":8888")
}
curl -i http://localhost:8888/api/v1/people/get/@me
HTTP/1.1 404 Not Found
Content-Type: application/json
Date: Sat, 22 Oct 2016 14:50:00 GMT
Content-Length: 220
{
"method": "people.get",
"params": {
"userId": "@me"
},
"error": {
"code": 404,
"message": "UserId not found",
"errors": [
{
"message": "Group or User not found"
}
]
}
}
All the contributors are welcome. If you would like to be the contributor please accept some rules.
Thank you for your understanding!
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.