johnsonjh/gfcptun

View on GitHub
client/config.go

Summary

Maintainability
A
0 mins
Test Coverage
package main

import (
    "encoding/json"
    "os"
)

// Config for client
type Config struct {
    LocalAddr    string `json:"localaddr"`
    RemoteAddr   string `json:"remoteaddr"`
    Key          string `json:"key"`
    Mode         string `json:"mode"`
    Conn         int    `json:"conn"`
    AutoExpire   int    `json:"autoexpire"`
    ScavengeTTL  int    `json:"scavengettl"`
    MTU          int    `json:"mtu"`
    SndWnd       int    `json:"sndwnd"`
    RcvWnd       int    `json:"rcvwnd"`
    DataShard    int    `json:"datashard"`
    ParityShard  int    `json:"parityshard"`
    DSCP         int    `json:"dscp"`
    NoComp       bool   `json:"nocomp"`
    AckNodelay   bool   `json:"acknodelay"`
    NoDelay      int    `json:"nodelay"`
    Interval     int    `json:"interval"`
    Resend       int    `json:"resend"`
    NoCongestion int    `json:"nc"`
    SockBuf      int    `json:"sockbuf"`
    SmuxVer      int    `json:"smuxver"`
    SmuxBuf      int    `json:"smuxbuf"`
    StreamBuf    int    `json:"streambuf"`
    KeepAlive    int    `json:"keepalive"`
    Log          string `json:"log"`
    SnsiLog      string `json:"snsilog"`
    SnsiPeriod   int    `json:"snsiperiod"`
    Quiet        bool   `json:"quiet"`
    TCP          bool   `json:"tcp"`
}

func parseJSONConfig(config *Config, path string) error {
    file, err := os.Open(path) // For read access.
    if err != nil {
        return err
    }
    defer file.Close()

    return json.NewDecoder(file).Decode(config)
}