Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Unexpose the options struct

  • Loading branch information...
commit 9968c32969e6a7637e348a0910ac48e9d17ad502 1 parent 05cc323
@caio authored
Showing with 9 additions and 9 deletions.
  1. +9 −9 papi.go
View
18 papi.go
@@ -15,7 +15,7 @@ import (
"strings"
)
-type Options struct {
+type options struct {
Raw bool
CSV bool
TSV bool
@@ -51,8 +51,8 @@ Modes:
input instead of processing it.
`
-func parseOptions() Options {
- var opts Options
+func parseOptions() options {
+ var opts options
flag.StringVar(&opts.Delimiter, "delimiter", "", "")
flag.StringVar(&opts.Delimiter, "d", "", "")
@@ -127,7 +127,7 @@ func readLineSafe(reader *bufio.Reader) (str string, err error) {
// makeMap splits a given line and processes it to generate a
// map which will be serialized to JSON.
-func makeMap(line string, opts Options) map[string]interface{} {
+func makeMap(line string, opts options) map[string]interface{} {
inputMap := make(map[string]interface{})
fields := splitMulti(opts, line)
@@ -196,9 +196,9 @@ func makeMap(line string, opts Options) map[string]interface{} {
return inputMap
}
-// splitMulti uses the Options struct to decide how to split
+// splitMulti uses the options struct to decide how to split
// a given string
-func splitMulti(opts Options, line string) (fields []string) {
+func splitMulti(opts options, line string) (fields []string) {
if opts.CSV {
// Use a real CSV reader when --csv is on
parser := csv.NewReader(strings.NewReader(line))
@@ -220,7 +220,7 @@ func splitMulti(opts Options, line string) (fields []string) {
// emitJson is the main proper loop of papi, it writes
// a JSON string to the given channel
-func emitJson(opts Options, inputStream *bufio.Reader, output chan []byte) {
+func emitJson(opts options, inputStream *bufio.Reader, output chan []byte) {
for {
line, err := readLineSafe(inputStream)
@@ -262,7 +262,7 @@ func emitJson(opts Options, inputStream *bufio.Reader, output chan []byte) {
// setupServer starts an HTTP server listening on the configured
// port and serving under /papi the JSON data received through
// the given read-only channel
-func setupServer(opts Options, in <-chan []byte) {
+func setupServer(opts options, in <-chan []byte) {
http.HandleFunc("/papi", func(w http.ResponseWriter, r *http.Request) {
// Block every method but GET
@@ -294,7 +294,7 @@ func setupServer(opts Options, in <-chan []byte) {
// makeReaker simply wraps a goroutine that calls emitJson
// using STDIN as the data source
-func makeReader(opts Options) <-chan []byte {
+func makeReader(opts options) <-chan []byte {
channel := make(chan []byte)
bufferedStdin := bufio.NewReader(os.Stdin)
Please sign in to comment.
Something went wrong with that request. Please try again.