Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/allenyoung-coder/iris
Iris is a fast, simple yet fully featured and very efficient web framework for Go.
Iris provides a beautifully expressive and easy to use foundation for your next website or API.
Finally, a real expressjs equivalent for the Go Programming Language.
Learn what others say about Iris and star this github repository to stay up to date.
The only requirement is the Go Programming Language
$ go get -u github.com/kataras/iris
Iris takes advantage of the vendor directory feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
Updated at: Tuesday, 21 November 2017
The Iris philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Keep note that, so far, iris is the fastest web framework ever created in terms of performance.
Iris does not force you to use any specific ORM or template engine. With support for the most used template engines, you can quickly craft the perfect application.
$ cat example.go
package main
import "github.com/kataras/iris"
func main() {
app := iris.Default()
app.Get("/ping", func(ctx iris.Context) {
ctx.JSON(iris.Map{
"message": "pong",
})
})
// Listen and serve on http://localhost:8080.
app.Run(iris.Addr(":8080"))
}
$ go run example.go
Now listening on: http://localhost:8080
Application Started. Press CTRL+C to shut down.
_
func main() {
// Creates an application with default middleware:
// logger and recovery (crash-free) middleware.
app := iris.Default()
app.Get("/someGet", getting)
app.Post("/somePost", posting)
app.Put("/somePut", putting)
app.Delete("/someDelete", deleting)
app.Patch("/somePatch", patching)
app.Head("/someHead", head)
app.Options("/someOptions", options)
app.Run(iris.Addr(":8080"))
}
func main() {
app := iris.Default()
// This handler will match /user/kataras but will not match neither /user/ or /user.
app.Get("/user/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.Writef("Hello %s", name)
})
// This handles the /user/kataras/42
// and fires 400 bad request if /user/kataras/string.
// The "else 400" is optionally:
// by-default it will fire 404 not found if alphanumeric instead
// of number passed on the "age" parameter.
app.Get("/user/{name:string}/{age:int else 400}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
age, _ := ctx.Params().GetInt("age")
ctx.Writef("%s is %d years old", name, age)
})
// However, this one will match /action/{user}/star and also /action/{user}/stars
// or even /action/{user}/likes/page/2.
// It should match anything after the /action/{user}/
// except the /action/{user}/static which is handled by the below route.
app.Get("/action/{user:string}/{action:path}", func(ctx iris.Context) {
user := ctx.Params().Get("user")
action := ctx.Params().Get("action")
ctx.Writef("user: %s | action: %s", user, action)
})
// Unlike other frameworks and routers,
// Iris is smart enough to understand that this is not the previous,
// wildcard of type path route, it should only match the /action/{user}/static.
app.Get("/action/{user:string}/static", func(ctx iris.Context) {
user := ctx.Params().Get("user")
ctx.Writef("static path for user: %s", user)
})
// http://localhost:8080/user/kataras
// http://localhost:8080/user/kataras/25
// http://localhost:8080/action/kataras/upgrade
// http://localhost:8080/action/kataras/static
app.Run(iris.Addr(":8080"))
}
If parameter type is missing then defaults to
string
, therefore{name:string}
and{name}
do the same exactly thing.
Learn more about path parameter's types by navigating here.
$ cat _examples/cookies/basic/main.go
package main
import "github.com/kataras/iris"
func newApp() *iris.Application {
app := iris.New()
// Set A Cookie.
app.Get("/cookies/{name}/{value}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
value := ctx.Params().Get("value")
ctx.SetCookieKV(name, value)
ctx.Writef("cookie added: %s = %s", name, value)
})
// Retrieve A Cookie.
app.Get("/cookies/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
value := ctx.GetCookie(name)
ctx.WriteString(value)
})
// Delete A Cookie.
app.Delete("/cookies/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.RemoveCookie(name)
ctx.Writef("cookie %s removed", name)
})
return app
}
func main() {
app := newApp()
// GET: http://localhost:8080/cookies/my_name/my_value
// GET: http://localhost:8080/cookies/my_name
// DELETE: http://localhost:8080/cookies/my_name
app.Run(iris.Addr(":8080"))
}
http.Cookie
: ctx.SetCookie(&http.Cookie{...})
ctx.SetCookieKV(name, value, iris.CookiePath("/custom/path/cookie/will/be/stored"))
.ctx.SetCookieKV(name, value, iris.CookieCleanPath /* or iris.CookiePath("") */)
iris.CookieExpires(time.Duration)
iris.CookieHTTPOnly(false)
ctx.Request().Cookie(name)
is also available, it's the net/http
approachpackage main
import (
"fmt"
"testing"
"github.com/kataras/iris/httptest"
)
// go test -v -run=TestCookiesBasic$
func TestCookiesBasic(t *testing.T) {
app := newApp()
e := httptest.New(t, app, httptest.URL("http://example.com"))
cookieName, cookieValue := "my_cookie_name", "my_cookie_value"
// Test Set A Cookie.
t1 := e.GET(fmt.Sprintf("/cookies/%s/%s", cookieName, cookieValue)).Expect().Status(httptest.StatusOK)
t1.Cookie(cookieName).Value().Equal(cookieValue) // validate cookie's existence, it should be there now.
t1.Body().Contains(cookieValue)
path := fmt.Sprintf("/cookies/%s", cookieName)
// Test Retrieve A Cookie.
t2 := e.GET(path).Expect().Status(httptest.StatusOK)
t2.Body().Equal(cookieValue)
// Test Remove A Cookie.
t3 := e.DELETE(path).Expect().Status(httptest.StatusOK)
t3.Body().Contains(cookieName)
t4 := e.GET(path).Expect().Status(httptest.StatusOK)
t4.Cookies().Empty()
t4.Body().Empty()
}
First of all, the most correct way to begin with a web framework is to learn the basics of the programming language and the standard http
capabilities, if your web application is a very simple personal project without performance and maintainability requirements you may want to proceed just with the standard packages. After that follow the guidelines:
Did you build something similar? Let us know!
Iris has a great collection of handlers[1][2] that you can use side by side with your web apps. However you are not limited to them - you are free to use any third-party middleware that is compatible with the net/http package, _examples/convert-handlers will show you the way.
Iris, unlike others, is 100% compatible with the standards and that's why the majority of the big companies that adapt Go to their workflow, like a very famous US Television Network, trust Iris; it's up-to-date and it will be always aligned with the std net/http
package which is modernized by the Go Authors on each new release of the Go Programming Language.
For more information about contributing to the Iris project please check the CONTRIBUTING.md file.
There are many companies and start-ups looking for Go web developers with Iris experience as requirement, we are searching for you every day and we post those information via our facebook page, like the page to get notified, we have already posted some of them.
Thank you to all our backers! 🙏 Become a backer
Iris is licensed under the 3-Clause BSD License. Iris is 100% free and open-source software.
For any questions regarding the license please send e-mail.
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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.