Skip to content

Commit

Permalink
Merge pull request #3 from ahmedkamals/feature/documnetation-update
Browse files Browse the repository at this point in the history
Updated documentation
  • Loading branch information
architeacher committed Oct 15, 2017
2 parents d1d56dc + 999183d commit d682bdd
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -29,7 +29,7 @@ Table of Contents
* [Installation](#installation)
* [Test Driver](#test-driver)
* [Tests](#tests)
* [Coding - __Structure & Design__](#coding---__structure-&-design__)
* [Coding - __Structure & Design__](#coding---structure--design)
* [Todo](#todo)

Overview
Expand Down Expand Up @@ -73,10 +73,18 @@ A->B: <disconnect>

The proxy has a reporting features like:

- Reporting stats when sending `SIGUSR2` signal to the process and over HTTP.
- Health check over HTTP.
- Reporting stats in JSON format to stdout when sending `SIGUSR2` signal to the process.
- Reporting stats in JSON format over HTTP "/stats" or "/metrics.
- Health check over HTTP "/health" or "/status".
- Data recovery after failure using a sliding window of `10s` time frame.

##### JSON Sample Response

```json
{"msg_total":10,"msg_req":10,"msg_ack":8,"msg_nak":2,"request_rate_1s":0.005,"request_rate_10s":0.004,"response_rate_1s":0.004,"response_rate_10s":0.003}

```

Getting Started
---------------

Expand Down
14 changes: 14 additions & 0 deletions main.go
Expand Up @@ -2,9 +2,23 @@ package main

import (
"github.com/ahmedkamals/foo-protocol-proxy/app"
"github.com/ahmedkamals/foo-protocol-proxy/utils"
"os"
)

func main() {
colorable := utils.NewColorable(os.Stdout)
println(colorable.Wrap(
[]string{`
_____ ____ _ _ ____
| ___|__ ___ | _ \ _ __ ___ | |_ ___ ___ ___ | | | _ \ _ __ _____ ___ _
| |_ / _ \ / _ \ | |_) | '__/ _ \| __/ _ \ / __/ _ \| | | |_) | '__/ _ \ \/ / | | |
| _| (_) | (_) | | __/| | | (_) | || (_) | (_| (_) | | | __/| | | (_) > <| |_| |
|_| \___/ \___/ |_| |_| \___/ \__\___/ \___\___/|_| |_| |_| \___/_/\_\\__, |
|___/ `,
}[0],
utils.FGBlue,
))
dispatcher := new(app.Dispatcher)
dispatcher.Run()
}
101 changes: 101 additions & 0 deletions utils/colorable.go
@@ -0,0 +1,101 @@
package utils

import (
"fmt"
"io"
"strconv"
"strings"
)

type (
// Colorable interface for console colors.
Colorable struct {
output io.Writer
}
// ColorValue type.
ColorValue int
)

const (
// Escape value at the console output.
Escape = "\x1b"
)

// Font effects.
const (
Reset ColorValue = iota
Bold
Faint
Italic
BlinkSlow
BlinkRapid
ReverseVideo
Concealed
CrossedOut
)

// Foreground text colors.
const (
FGBlack ColorValue = iota + 30
FGRed
FGGreen
FGYellow
FGBlue
Magenta
FGCyan
FGWhite
)

// Background text colors.
const (
BGBlack ColorValue = iota + 40
BGRed
BGGReen
BGYellow
BGBlue
BGMagenta
BGCyan
BGWhite
)

// NewColorable allocates and returns a new Colorable.
func NewColorable(output io.Writer) *Colorable {
return &Colorable{
output: output,
}
}

// Set sets a group of color values for the next output operations.
func (c *Colorable) Set(color ...ColorValue) *Colorable {
fmt.Fprintf(c.output, c.format(color...))

return c
}

// Reset resets the color value to the default.
func (c *Colorable) Reset() {
fmt.Fprintf(c.output, "%s[%dm", Escape, Reset)
}

// Wrap wraps a passed a string with a color values.
func (c *Colorable) Wrap(str string, color ...ColorValue) string {
return fmt.Sprintf("%s%s%s", c.format(color...), str, c.resetFormat())
}

func (c *Colorable) format(color ...ColorValue) string {
return fmt.Sprintf("%s[%sm", Escape, c.sequence(color...))
}

func (c *Colorable) resetFormat() string {
return fmt.Sprintf("%s[%dm", Escape, Reset)
}

func (c *Colorable) sequence(color ...ColorValue) string {
format := make([]string, len(color))

for key, value := range color {
format[key] = strconv.Itoa(int(value))
}

return strings.Join(format, ";")
}
2 changes: 2 additions & 0 deletions utils/doc.go
@@ -0,0 +1,2 @@
// Package utils contains utilities used in the project.
package utils

0 comments on commit d682bdd

Please sign in to comment.