indigo

package module
v0.15.9 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 25 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. However, it isn't complete yet.

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.15.9"

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(port uint16, 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(port uint16, cert, key string) *App

func (*App) Listen added in v0.15.0

func (a *App) Listen(port uint16, enc encryption.Encryption, optionalConstructor ...ListenerConstructor) *App

Listen adds a new listener

func (*App) NotifyOnStart added in v0.15.0

func (a *App) NotifyOnStart(cb func()) *App

NotifyOnStart 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) NotifyOnStop added in v0.15.0

func (a *App) NotifyOnStop(cb func()) *App

NotifyOnStop 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.Router) 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) TLS added in v0.15.0

func (a *App) TLS(port uint16, constructor ListenerConstructor) *App

func (*App) Tune added in v0.15.0

func (a *App) Tune(s settings.Settings) *App

Tune replaces default settings.

type Listener added in v0.15.0

type Listener struct {
	Port        uint16
	Constructor ListenerConstructor
	Encryption  encryption.Encryption
}

type ListenerConstructor added in v0.15.0

type ListenerConstructor func(network, addr string) (net.Listener, error)

Jump to

Keyboard shortcuts

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