<commit_before># Lion [![Build Status](https://img.shields.io/travis/celrenheit/lion.svg?style=flat-square)](https://travis-ci.org/celrenheit/lion) [![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](https://godoc.org/github.com/celrenheit/lion) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/celrenheit/lion?style=flat-square)](https://goreportcard.com/report/github.com/celrenheit/lion)

Lion is a [fast](#benchmarks) HTTP router for Go with support for middlewares for building modern scalable modular REST APIs.

![Lion's Hello World GIF](https://raw.githubusercontent.com/celrenheit/gifs/master/lion/hello-speed2-sm.min.gif)

## Lion v2

If you are starting a new project, please consider starting out using the [_v2_](https://github.com/celrenheit/lion/tree/v2) 
and the new [documentation](https://godoc.org/gopkg.in/celrenheit/lion.v2) branch. It contains a few breaking changes.

The most important one is that it now uses native [http.Handler](https://golang.org/pkg/net/http/#Handler).

## Features

* **Context-Aware**: Lion uses the de-facto standard [net/Context](https://golang.org/x/net/context) for storing route params and sharing variables between middlewares and HTTP handlers. It [_could_](https://github.com/golang/go/issues/14660) be integrated in the [standard library](https://github.com/golang/go/issues/13021) for Go 1.7 in 2016.
* **Modular**: You can define your own modules to easily build a scalable architecture
* **REST friendly**: You can define modules to groups http resources together.
* **Host**: Match hosts. Each host can get its own content.
* **Zero allocations**: Lion generates zero garbage[*](#benchmarks).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents

  - [Install/Update](#installupdate)
  - [Hello World](#hello-world)
  - [Getting started with modules and resources](#getting-started-with-modules-and-resources)
  - [Handlers](#handlers)
    - [Using Handlers](#using-handlers)
    - [Using HandlerFuncs](#using-handlerfuncs)
    - [Using native http.Handler](#using-native-httphandler)
      - [Using native http.Handler with *lion.Wrap()*](#using-native-httphandler-with-lionwrap)
      - [Using native http.Handler with *lion.WrapFunc()*](#using-native-httphandler-with-lionwrapfunc)
  - [Middlewares](#middlewares)
    - [Using Named Middlewares](#using-named-middlewares)
    - [Using Negroni Middlewares](#using-negroni-middlewares)
  - [Match Hosts](#match-hosts)
  - [Resources](#resources)
  - [Examples](#examples)
    - [Using GET, POST, PUT, DELETE http methods](#using-get-post-put-delete-http-methods)
    - [Using middlewares](#using-middlewares)
    - [Group routes by a base path](#group-routes-by-a-base-path)
    - [Mounting a router into a base path](#mounting-a-router-into-a-base-path)
    - [Default middlewares](#default-middlewares)
- [Custom Middlewares](#custom-middlewares)
    - [Custom Logger example](#custom-logger-example)
  - [Benchmarks](#benchmarks)
  - [License](#license)
  - [Todo](#todo)
  - [Credits](#credits)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Install/Update

```shell
$ go get -u github.com/celrenheit/lion
```


## Hello World

```go<commit_msg>Change import path for lion v1<commit_after># Lion [![Build Status](https://img.shields.io/travis/celrenheit/lion.svg?style=flat-square)](https://travis-ci.org/celrenheit/lion) [![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](https://godoc.org/github.com/celrenheit/lion) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/celrenheit/lion?style=flat-square)](https://goreportcard.com/report/github.com/celrenheit/lion)

Lion is a [fast](#benchmarks) HTTP router for Go with support for middlewares for building modern scalable modular REST APIs.

![Lion's Hello World GIF](https://raw.githubusercontent.com/celrenheit/gifs/master/lion/hello-speed2-sm.min.gif)

## Lion v2

If you are starting a new project, please consider starting out using the [_v2_](https://github.com/celrenheit/lion/tree/v2) 
and the new [documentation](https://godoc.org/gopkg.in/celrenheit/lion.v2) branch. It contains a few breaking changes.

The most important one is that it now uses native [http.Handler](https://golang.org/pkg/net/http/#Handler).

# Important

If you are using lion v1, please change your import path to `gopkg.in/celrenheit/lion.v1`.

You can get lion via:
```shell
go get -u gopkg.in/celrenheit/lion.v1
```

## Features

* **Context-Aware**: Lion uses the de-facto standard [net/Context](https://golang.org/x/net/context) for storing route params and sharing variables between middlewares and HTTP handlers. It [_could_](https://github.com/golang/go/issues/14660) be integrated in the [standard library](https://github.com/golang/go/issues/13021) for Go 1.7 in 2016.
* **Modular**: You can define your own modules to easily build a scalable architecture
* **REST friendly**: You can define modules to groups http resources together.
* **Host**: Match hosts. Each host can get its own content.
* **Zero allocations**: Lion generates zero garbage[*](#benchmarks).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents

  - [Install/Update](#installupdate)
  - [Hello World](#hello-world)
  - [Getting started with modules and resources](#getting-started-with-modules-and-resources)
  - [Handlers](#handlers)
    - [Using Handlers](#using-handlers)
    - [Using HandlerFuncs](#using-handlerfuncs)
    - [Using native http.Handler](#using-native-httphandler)
      - [Using native http.Handler with *lion.Wrap()*](#using-native-httphandler-with-lionwrap)
      - [Using native http.Handler with *lion.WrapFunc()*](#using-native-httphandler-with-lionwrapfunc)
  - [Middlewares](#middlewares)
    - [Using Named Middlewares](#using-named-middlewares)
    - [Using Negroni Middlewares](#using-negroni-middlewares)
  - [Match Hosts](#match-hosts)
  - [Resources](#resources)
  - [Examples](#examples)
    - [Using GET, POST, PUT, DELETE http methods](#using-get-post-put-delete-http-methods)
    - [Using middlewares](#using-middlewares)
    - [Group routes by a base path](#group-routes-by-a-base-path)
    - [Mounting a router into a base path](#mounting-a-router-into-a-base-path)
    - [Default middlewares](#default-middlewares)
- [Custom Middlewares](#custom-middlewares)
    - [Custom Logger example](#custom-logger-example)
  - [Benchmarks](#benchmarks)
  - [License](#license)
  - [Todo](#todo)
  - [Credits](#credits)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Install/Update

```shell
$ go get -u gopkg.in/celrenheit/lion.v1
```


## Hello World

```go
{'fraction_non_alphanumeric': 0.1525686136523575, 'fraction_numerical': 0.008022519352568614, 'mean_word_length': 4.5, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6969980', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2233, 'n_words': 546}