indigo

package module
v0.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 23 Imported by: 1

README

This is just a logo

Indigo is a web-framework, designed to be readable, handy, yet performant (blazingly fast I would even say)

Documentation

Documentation is available here. It may be incomplete or not represent the actual state, so make sure the version in documentation corresponds to the latest release.

Hello, world!

package main

import (
	"log"

	"github.com/indigo-web/indigo"
	"github.com/indigo-web/indigo/http"
	"github.com/indigo-web/indigo/router/inbuilt"
)

func HelloWorld(request *http.Request) *http.Response {
	return http.String(request, "Hello, world!")
}

func Log(request *http.Request) *http.Response {
	text, err := request.Body.String()
	if err != nil {
		return http.Error(request, err)
	}

	log.Printf("%s says: %s", request.Remote, text)
	return http.String(request, text)
}

func main() {
	r := inbuilt.New()
	r.Resource("/").
		Get(HelloWorld).
		Post(Log)

	err := indigo.New(":8080").Serve(r)
	if err != nil {
		log.Fatal(err)
	}
}

You can find more examples in examples/.

Documentation

Index

Constants

View Source
const Version = "v0.16.3"

Variables

This section is empty.

Functions

This section is empty.

Types

type App added in v0.15.0

type App struct {
	// contains filtered or unexported fields
}

App is just a struct with addr and shutdown channel that is currently not used. Planning to replace it with context.WithCancel()

func New added in v0.15.0

func New(addr string) *App

New returns a new App instance.

func (*App) AutoHTTPS added in v0.15.0

func (a *App) AutoHTTPS(addr string, domains ...string) *App

AutoHTTPS enables HTTPS-mode using autocert or generates self-signed certificates if using local host

func (*App) GracefulStop added in v0.15.0

func (a *App) GracefulStop()

GracefulStop stops accepting new connections, but keeps serving old ones.

NOTE: the call isn't blocking. So by that, after the method returned, the server will be still working

func (*App) HTTPS added in v0.15.0

func (a *App) HTTPS(addr string, cert, key string) *App

func (*App) Listen added in v0.15.0

func (a *App) Listen(addr string, optListener ...Listener) *App

Listen adds a new listener

func (*App) OnBind added in v0.16.0

func (a *App) OnBind(cb func(addr string)) *App

OnBind calls the passed callback for every address, that was bound without any errors

func (*App) OnStart added in v0.16.0

func (a *App) OnStart(cb func()) *App

OnStart calls the callback at the moment, when all the servers are started. However, it isn't strongly guaranteed that they'll be able to accept new connections immediately

func (*App) OnStop added in v0.16.0

func (a *App) OnStop(cb func()) *App

OnStop calls the callback at the moment, when all the servers are down. It's guaranteed, that at the moment as the callback is called, the server isn't able to accept any new connections and all the clients are already disconnected

func (*App) Serve added in v0.15.0

func (a *App) Serve(r router.Fabric) error

Serve starts the web-application. If nil is passed instead of a router, empty inbuilt will be used.

func (*App) Stop added in v0.15.0

func (a *App) Stop()

Stop stops the whole application immediately.

NOTE: the call isn't blocking. So by that, after the method returned, the server will still be working

func (*App) Tune added in v0.15.0

func (a *App) Tune(cfg config.Config) *App

Tune replaces default config.

type Listener added in v0.15.0

type Listener struct {
	Listen  listenerFactory
	Handler listenerHandler
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL