indigo

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 17 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"
  "github.com/indigo-web/indigo/http"
  "github.com/indigo-web/indigo/router/inbuilt"
)

const addr = "0.0.0.0:9090"

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

func main() {
  router := inbuilt.New()
  router.Resource("/").
    Get(MyHandler).
    Post(MyHandler)

  app := indigo.NewApp(addr)
  if err := app.Serve(router); err != nil {
    log.Fatal(err)
  }
  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{

	"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 decode.DecoderFactory)

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