joehttp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: BSD-3-Clause Imports: 11 Imported by: 1

README

Joe Bot - HTTP Server

Providing HTTP integrations for Joe. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library.

Getting Started

This library is packaged as Go module. You can get it via:

go get github.com/go-joe/http-server

Example usage

In order to let your bot listen to HTTP requests you should pass the http.Server(…) module when creating a new bot:

package main

import (
	"github.com/go-joe/joe"
	"github.com/go-joe/http-server"
)

func main() {
	b := joe.New("example-bot",
		joehttp.Server("localhost:12345"),
		…
	)
	
	err := b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

When the server receives a request, it will emit it to the bots brain as joehttp.RequestEvent.

Built With

  • zap - Blazing fast, structured, leveled logging in Go
  • testify - A simple unit test library

Contributing

If you want to hack on this repository, please read the short CONTRIBUTING.md guide first.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Friedrich Große - Initial work - fgrosse

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Documentation

Overview

Package joehttp contains an HTTP server integrations for the Joe bot library https://github.com/go-joe/joe

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Server

func Server(path string, opts ...Option) joe.Module

Server returns a joe Module that runs an HTTP server to receive HTTP requests and emit them as events. This Module is mainly meant to be used to integrate a Bot with other systems that send events via HTTP (e.g. pull requests on GitHub).

Types

type Option added in v0.4.0

type Option func(*config) error

An Option is used to configure the HTTP server.

func WithLogger added in v0.4.0

func WithLogger(logger *zap.Logger) Option

WithLogger can be used to inject a different logger for the HTTP server.

func WithReadTimeout added in v0.4.0

func WithReadTimeout(d time.Duration) Option

WithReadTimeout sets the servers maximum duration for reading the entire HTTP request, including the body.

func WithTLS added in v0.4.0

func WithTLS(certFile, keyFile string) Option

WithTLS enables serving HTTP requests via TLS.

func WithTLSConfig added in v0.4.0

func WithTLSConfig(tlsConf *tls.Config) Option

WithTLSConfig can be used in combination with the WithTLS(…) option to configure the HTTPS server.

func WithTimeouts added in v0.4.0

func WithTimeouts(d time.Duration) Option

WithTimeouts sets both the read and write timeout of the HTTP server to the same given value.

func WithTrustedHeader added in v0.5.0

func WithTrustedHeader(header string) Option

WithTrustedHeader sets the name of the header from which client IPs will be populated.

func WithWriteTimeout added in v0.4.0

func WithWriteTimeout(d time.Duration) Option

WithWriteTimeout sets the servers maximum duration before timing out writes of the HTTP response.

type RequestEvent

type RequestEvent struct {
	Header     http.Header
	Method     string
	URL        *url.URL
	RemoteAddr string
	Body       []byte
}

RequestEvent corresponds to an HTTP request that was received by the server.

Jump to

Keyboard shortcuts

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