![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.