indigo

package module
v2.3.1-beta Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 15 Imported by: 1

README

This is just a logo

Indigo is non-idiomatic, but focusing on simplicity and performance web-server

It provides such features:

  • Streaming-based body processing
  • Server-wide settings
  • Response object constructor
  • Middlewares
  • Endpoint groups
  • Connection hijacking

Hello, world!

package main

import (
  "log"
  
  "github.com/indigo-web/indigo/v2"
  "github.com/indigo-web/indigo/v2/http"
  "github.com/indigo-web/indigo/v2/router/inbuilt"
)

var addr = "localhost:9090"

func MyHandler(request *http.Request) http.Response {
  return http.RespondTo(request).WithBody("Hello, world!")
}

func main() {
  router := inbuilt.NewRouter()
  router.Get("/", MyHandler)

  app := indigo.NewApp(addr)
  log.Fatal(app.Serve(router))
}

More examples in examples/ folder.

Project workspace (TODO list included): trello.com/w/indigowebserver

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHeaders = map[string][]string{
	"Content-Type": {defaultContentType},

	"Accept-Encodings": nil,
}

DefaultHeaders are headers that are going to be sent unless they were overridden by user.

WARNING: if you want to edit them, do it using Application.AddDefaultHeader or Application.DeleteDefaultHeader instead

Functions

This section is empty.

Types

type Application

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

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

func NewApp

func NewApp(addr string) *Application

NewApp returns a new application object with initialized shutdown chan

func (*Application) AddContentDecoder

func (a *Application) AddContentDecoder(token string, decoder encodings.Decoder)

AddContentDecoder simply adds a new content decoder

func (*Application) AddDefaultHeader

func (a *Application) AddDefaultHeader(key string, values ...string)

func (*Application) DeleteDefaultHeader

func (a *Application) DeleteDefaultHeader(key string)

func (*Application) Serve

func (a *Application) Serve(r router.Router, optionalSettings ...settings.Settings) error

Serve takes a router and someSettings, that must be only 0 or 1 elements otherwise, error is returned Also, if specified, Accept-Encodings default header's value will be set here

func (*Application) SetDefaultHeaders

func (a *Application) SetDefaultHeaders(headers map[string][]string)

SetDefaultHeaders overrides default headers to a passed ones. Doing this, make sure you know what are you doing

func (*Application) Shutdown

func (a *Application) Shutdown()

Shutdown gracefully shutting down the server. It is not blocking, server being shut down right after calling this method is not guaranteed, because tcp server will wait for the next connection, and only then he'll be able to receive a shutdown notify. Moreover, tcp server will wait until all the existing connections will be closed

func (*Application) Wait

func (a *Application) Wait()

Wait waits for tcp server to shut down

Jump to

Keyboard shortcuts

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