Categorygithub.com/go-siris/siris
modulepackage
7.4.0+incompatible
Repository: https://github.com/go-siris/siris.git
Documentation: pkg.go.dev

# README

Logo

A fast, cross-platform and efficient web framework with robust set of well-designed features, written entirely in Go.

Build status Report card Support forum Examples Godocs Chat

Build your own web applications and portable APIs with the highest performance and countless potentials.

If you're coming from Node.js world, this is the expressjs++ equivalent for the Go Programming Language.

Table of contents

Installation

The only requirement is the Go Programming Language, at least version 1.8

$ go get -u github.com/go-siris/siris

Siris uses the vendor directory feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.

package main

import (
    "github.com/go-siris/siris"
    "github.com/go-siris/siris/context"
    "github.com/go-siris/siris/view"
)

// User is just a bindable object structure.
type User struct {
    Username  string `json:"username"`
    Firstname string `json:"firstname"`
    Lastname  string `json:"lastname"`
    City      string `json:"city"`
    Age       int    `json:"age"`
}

func main() {
    app := siris.New()

    // Define templates using the std html/template engine.
    // Parse and load all files inside "./views" folder with ".html" file extension.
    // Reload the templates on each request (development mode).
    app.AttachView(view.HTML("./views", ".html").Reload(true))

    // Regster custom handler for specific http errors.
    app.OnErrorCode(siris.StatusInternalServerError, func(ctx context.Context) {
    	// .Values are used to communicate between handlers, middleware.
    	errMessage := ctx.Values().GetString("error")
    	if errMessage != "" {
    		ctx.Writef("Internal server error: %s", errMessage)
    		return
    	}

    	ctx.Writef("(Unexpected) internal server error")
    })

    app.Use(func(ctx context.Context) {
    	ctx.Application().Logger().Info("Begin request for path: %s", ctx.Path())
    	ctx.Next()
    })

    // app.Done(func(ctx context.Context) {})

    // Method POST: http://localhost:8080/decode
    app.Post("/decode", func(ctx context.Context) {
    	var user User
    	ctx.ReadJSON(&user)
    	ctx.Writef("%s %s is %d years old and comes from %s", user.Firstname, user.Lastname, user.Age, user.City)
    })

    // Method GET: http://localhost:8080/encode
    app.Get("/encode", func(ctx context.Context) {
    	doe := User{
    		Username:  "Johndoe",
    		Firstname: "John",
    		Lastname:  "Doe",
    		City:      "Neither FBI knows!!!",
    		Age:       25,
    	}

    	ctx.JSON(doe)
    })

    // Method GET: http://localhost:8080/profile/anytypeofstring
    app.Get("/profile/{username:string}", profileByUsername)

    usersRoutes := app.Party("/users", logThisMiddleware)
    {
    	// Method GET: http://localhost:8080/users/42
    	usersRoutes.Get("/{id:int min(1)}", getUserByID)
    	// Method POST: http://localhost:8080/users/create
    	usersRoutes.Post("/create", createUser)
    }

    // Listen for incoming HTTP/1.x & HTTP/2 clients on localhost port 8080.
    app.Run(siris.Addr(":8080"), siris.WithCharset("UTF-8"))
}

func logThisMiddleware(ctx context.Context) {
    ctx.Application().Logger().Info("Path: %s | IP: %s", ctx.Path(), ctx.RemoteAddr())

    // .Next is required to move forward to the chain of handlers,
    // if missing then it stops the execution at this handler.
    ctx.Next()
}

func profileByUsername(ctx context.Context) {
    // .Params are used to get dynamic path parameters.
    username := ctx.Params().Get("username")
    ctx.ViewData("Username", username)
    // renders "./views/users/profile.html"
    // with {{ .Username }} equals to the username dynamic path parameter.
    ctx.View("users/profile.html")
}

func getUserByID(ctx context.Context) {
    userID := ctx.Params().Get("id") // Or convert directly using: .Values().GetInt/GetInt64 etc...
    // your own db fetch here instead of user :=...
    user := User{Username: "username" + userID}

    ctx.XML(user)
}

func createUser(ctx context.Context) {
    var user User
    err := ctx.ReadForm(&user)
    if err != nil {
    	ctx.Values().Set("error", "creating user, read and parse form failed. "+err.Error())
    	ctx.StatusCode(siris.StatusInternalServerError)
    	return
    }
    // renders "./views/users/create_verification.html"
    // with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
    ctx.ViewData("", user)
    ctx.View("users/create_verification.html")
}

Feature Overview

FeatureMore Information
high performancebenchmark
Authenticationbasicauth oauth2 TODO JWT
Cachecache-markdown
Certificatesletsencrypt custom
Compressiongzip and deflate
Decode Json, Formsjson form
Encode Json, JsonP, XML, Forms, Markdownjson cache-markdown
Error handlingcustom [error handler] [panic handler]
http2 pushTODO add Documentation
LimitsRequestBody TODO add docu
Localizationi18n
Logger Enginesfile-logger request-logger
Routingrouting
Sessionssessions
Static Filesfile-server
Subdomains and Groupingsubdomains
Template HTML, django, pug(jade), handlebars, amberviews
ToolingTypescript integration + Web IDE
Websocketswebsockets

Documentation

Small but practical examples --they cover each feature.

Wanna create your own fast URL Shortener Service Using Siris? --click here to learn how.

Godocs --for deep understanding.

Hints --some performance hints and tooling.

Support

  • Chat Ask the Community for help
  • Post a feature request or report a bug, will help to make the framework even better.
  • :star: and watch the project, will notify you about updates.
  • :earth_americas: publish an article or share a tweet about siris.

Third Party Middleware

See THIRD-PARTY-MIDDLEWARE.md

Testing

The httptest package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, gavv.

A simple test is located to intermediate/httptest/main_test.go

Philosophy

The Siris philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs.

Siris does not force you to use any specific ORM or template engine. With support for the most popular template engines, you can quickly craft your perfect application.

People

The original author of Iris is @kataras. Before we forked to Siris.

However the real Success of Siris belongs to you with your bug reports and feature requests that made this Framework so Unique.

Version

Current: 7.3.4

Each new release is pushed to the master. It stays there until the next version. When a next version is released then the previous version goes to its own branch with gopkg.in as its import path (and its own vendor folder), in order to keep it working "for-ever".

Community members can request additional features or report a bug fix for a specific siris version.

Should I upgrade my Siris?

Developers are not forced to use the latest Siris version, they can use any version in production, they can update at any time they want.

Testers should upgrade immediately, if you're willing to use Siris in production you can wait a little more longer, transaction should be as safe as possible.

Where can I find older versions?

Each Siris version is independent. Only bug fixes, Router's API and experience are kept.

Previous versions can be found at releases page.

Previous Iris versions are archived at iris archive

License

Unless otherwise noted, the source files are distributed under the BSD-3-Clause License found in the LICENSE file.

Note that some third-party packages that you use with Siris may requires different license agreements.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package sessions provider.
Package typescript provides a typescript compiler with hot-reloader and optionally a cloud-based editor, called 'alm-tools'.
No description provided by the author
No description provided by the author

# Functions

Addr can be used as an argument for the `Run` method.
AutoTLS can be used as an argument for the `Run` method.
Default returns a new Application instance.
Listener can be used as an argument for the `Run` method.
New creates and returns a fresh empty Siris *Application instance.
Raw can be used as an argument for the `Run` method.
Server can be used as an argument for the `Run` method.
TLS can be used as an argument for the `Run` method.
ToHandler converts native http.Handler & http.HandlerFunc to context.Handler.
WithCharset sets the Charset setting.
WithConfiguration sets the "c" values to the framework's configurations.
WithOtherValue adds a value based on a key to the Other setting.
WithoutRemoteAddrHeader disables an existing request header name that can be used to validate the client's real IP.
WithRemoteAddrHeader enables or adds a new or existing request header name that can be used to validate the client's real IP.
WithTimeFormat sets the TimeFormat setting.

# Constants

DebugLevel logs are typically voluminous, and are usually disabled in production.
DPanicLevel logs are particularly important errors.
ErrorLevel logs are high-priority.
FatalLevel logs a message, then calls os.Exit(1).
InfoLevel is the default logging priority.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
MethodNone is a Virtual method to store the "offline" routes.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
These may or may not stay, you can use net/http's constants too.
NoLayout to disable layout for a particular template file Conversion for view.NoLayout.
PanicLevel logs a message, then panics.
RFC 7231, 6.3.3.
RFC 5842, 7.1.
RFC 7231, 6.6.3.
RFC 7231, 6.5.1.
RFC 7231, 6.5.8.
RFC 7231, 6.2.1.
RFC 7231, 6.3.2.
RFC 7231, 6.5.14.
RFC 4918, 11.4.
RFC 7231, 6.5.3.
RFC 7231, 6.4.3.
RFC 7231, 6.6.5.
RFC 7231, 6.5.9.
RFC 7231, 6.6.6.
RFC 3229, 10.4.1.
RFC 4918, 11.5.
RFC 7231, 6.6.1.
RFC 7231, 6.5.10.
RFC 4918, 11.3.
RFC 5842, 7.2.
RFC 7231, 6.5.5.
RFC 7231, 6.4.2.
RFC 7231, 6.4.1.
RFC 4918, 11.1.
RFC 6585, 6.
RFC 7231, 6.3.5.
RFC 7231, 6.3.4.
RFC 7231, 6.5.6.
RFC 2774, 7.
RFC 7231, 6.5.4.
RFC 7231, 6.6.2.
RFC 7232, 4.1.
RFC 7231, 6.3.1.
RFC 7233, 4.1.
RFC 7231, 6.5.2.
RFC 7538, 3.
RFC 7232, 4.2.
RFC 6585, 3.
RFC 2518, 10.1.
RFC 7235, 3.2.
RFC 7233, 4.4.
RFC 7231, 6.5.11.
RFC 6585, 5.
RFC 7231, 6.5.7.
RFC 7231, 6.5.12.
RFC 7231, 6.3.6.
RFC 7231, 6.4.4.
RFC 7231, 6.6.4.
RFC 7231, 6.2.2.
RFC 7168, 2.3.3.
RFC 7231, 6.4.7.
RFC 6585, 4.
RFC 7235, 3.1.
RFC 7725, 3.
RFC 4918, 11.2.
RFC 7231, 6.5.13.
RFC 7231, 6.5.15.
RFC 7231, 6.4.5.
RFC 2295, 8.1.
Version is the current version number of the Siris Web framework.
WarnLevel logs are more important than Info, but don't need individual human review.

# Variables

Amber view engine.
Cache provides cache capabilities to a route's handler.
CheckErr is the old `Must`.
Django view engine.
EnableQUICSupport turns on the Reuseport feature.
EnableReuseport turns on the Reuseport feature.
ErrServerClosed is returned by the Server's Serve, ServeTLS, ListenAndServe, and ListenAndServeTLS methods after a call to Shutdown or Close.
Handlebars view engine.
HTML view engine.
LimitRequestBodySize is a middleware which sets a request body size limit for all next handlers in the chain.
Pug view engine.
RegisterOnInterruptHook registers a global function to call when CTRL+C/CMD+C pressed or a unix kill command received.
TOML load the TOML Configuration.
WithFireMethodNotAllowed enanbles the FireMethodNotAllowed setting.
WithJSONInteratorReplacement enables JSONInteratorReplacement setting.
WithoutAutoFireStatusCode disables the AutoFireStatusCode setting.
WithoutBanner turns off the write banner on server startup.
WithoutBodyConsumptionOnUnmarshal disables BodyConsumptionOnUnmarshal setting.
WithoutInterruptHandler disables the automatic graceful server shutdown when control/cmd+C pressed.
WithoutPathCorrection disables the PathCorrection setting.
WithPathEscape enanbles the PathEscape setting.
YAML load the YAML Configuration.

# Structs

Application is responsible to manage the state of the application.

# Type aliases

Configurator is just an interface which accepts the framework instance.
TODO: When go 1.9 will be released split this file in order to separate the concepts.
TODO: When go 1.9 will be released split this file in order to separate the concepts.
TODO: When go 1.9 will be released split this file in order to separate the concepts.
TODO: When go 1.9 will be released split this file in order to separate the concepts.
Runner is just an interface which accepts the framework instance and returns an error.
TODO: When go 1.9 will be released split this file in order to separate the concepts.