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/4freewifi/goroute
A very simple URL router for net/http package based on regular expression.
The idea of http.Handler
is great because it is just an interface so
the developer can keep all the necessary info in its own
context. However, most of the web framework or routing package out
there only support http.HandleFunc
, which means the context must be
kept elsewhere. For example, consider the following program:
package main
import (
"fmt"
"net/http"
)
type MySrv struct {
hello string
}
func (m *MySrv) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", m.hello)
}
func main() {
srv := MySrv{"World"}
http.Handle("/", &srv)
http.ListenAndServe("localhost:8080", nil)
}
In case of web.go, if keeping the
original context MySrv
is required, this program will become
something like:
package main
import (
"fmt"
"net/http"
"github.com/hoisie/web"
)
type MySrv struct {
hello string
}
func (m *MySrv) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!\n", m.hello)
}
func main() {
srv := MySrv{"World"}
hello := func(ctx *web.Context, val string) {
for k,v := range ctx.Params {
fmt.Fprintln(ctx, k, v)
}
srv.ServeHTTP(ctx, ctx.Request)
}
web.Get("/(.*)", hello)
web.Run("localhost:8080")
}
Because of function closure, srv MySrv
is implicitly included in
hello
, and modifications made to srv
will implicitly affect
hello
. Explicit is better than implicit. Many other projects
suffer from similiar issue. However, the requirement of a simple URL
path router still exists, e.g. in case of RESTful like GET /users/<userid>
. A very thin layer that handles just routing and
doesn't get in the way of the original structure of net/http will be
handy.
Check goroute_test.go
.
Comparing to the original http.Handler, a new parameter pattern
is
required when you associate an Handler to a path . It should be a
regular expression with named capturing group, and every named
parentheses will be stored in the extra parameter map[string]string
introduced in goroute.Handler interface.
Visit http://godoc.org/github.com/4freewifi/goroute
Copyright 2015 John Lee john@4free.com.tw
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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.