-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into for_github
- Loading branch information
Showing
7 changed files
with
379 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variables: | ||
BINARY_NAME: $CI_PROJECT_NAME | ||
|
||
stages: | ||
- build | ||
|
||
build: | ||
stage: build | ||
image: golang:alpine | ||
script: | ||
- go build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var cfg map[string]string | ||
var inblacklist map[string]bool | ||
var inwhitelist map[string]bool | ||
|
||
// InitCfg read cfgfile variable | ||
func InitCfg(s string) { | ||
cfg = make(map[string]string) | ||
inblacklist = make(map[string]bool) | ||
inwhitelist = make(map[string]bool) | ||
|
||
f, err := os.Open(s) | ||
if err != nil { | ||
panic(fmt.Sprintf("Unable to read configuration file %s", s)) | ||
} | ||
defer f.Close() | ||
rd := bufio.NewReader(f) | ||
for { | ||
cfgline, err := rd.ReadString('\n') | ||
if err != nil { | ||
break | ||
} | ||
cfgline = strings.Trim(cfgline, " \n\r") | ||
cfgval := strings.SplitN(cfgline, "=", 2) | ||
if len(cfgval) < 2 { | ||
continue | ||
} | ||
switch { | ||
case cfgval[0] == "blacklist": | ||
inblacklist[cfgval[1]] = true | ||
case cfgval[0] == "whitelist": | ||
inwhitelist[cfgval[1]] = true | ||
default: | ||
cfg[cfgval[0]] = cfgval[1] | ||
} | ||
} | ||
} | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var cfg map[string]string | ||
var inblacklist map[string]bool | ||
var inwhitelist map[string]bool | ||
|
||
// InitCfg read cfgfile variable | ||
func InitCfg(s string) { | ||
cfg = make(map[string]string) | ||
inblacklist = make(map[string]bool) | ||
inwhitelist = make(map[string]bool) | ||
|
||
f, err := os.Open(s) | ||
if err != nil { | ||
panic(fmt.Sprintf("Unable to read configuration file %s", s)) | ||
} | ||
defer f.Close() | ||
rd := bufio.NewReader(f) | ||
for { | ||
cfgline, err := rd.ReadString('\n') | ||
if err != nil { | ||
break | ||
} | ||
cfgline = strings.Trim(cfgline, " \n\r") | ||
cfgval := strings.SplitN(cfgline, "=", 2) | ||
if len(cfgval) < 2 { | ||
continue | ||
} | ||
switch { | ||
case cfgval[0] == "blacklist": | ||
inblacklist[cfgval[1]] = true | ||
case cfgval[0] == "whitelist": | ||
inwhitelist[cfgval[1]] = true | ||
default: | ||
cfg[cfgval[0]] = cfgval[1] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"log/syslog" | ||
"os" | ||
"time" | ||
) | ||
|
||
var xlog *syslog.Writer | ||
|
||
func initSyslog(exe string) { | ||
var e error | ||
xlog, e = syslog.New(syslog.LOG_DAEMON|syslog.LOG_INFO, exe) | ||
if e == nil { | ||
log.SetOutput(xlog) | ||
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) // remove timestamp | ||
} | ||
} | ||
|
||
func writePidfile(pidfile string) { | ||
err := ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664) | ||
if err != nil { | ||
log.Output(1, "Unable to create pidfile "+pidfile) | ||
time.Sleep(20 * time.Second) | ||
} | ||
} | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"log/syslog" | ||
"os" | ||
"time" | ||
) | ||
|
||
var xlog *syslog.Writer | ||
|
||
func initSyslog(exe string) { | ||
var e error | ||
xlog, e = syslog.New(syslog.LOG_DAEMON|syslog.LOG_INFO, exe) | ||
if e == nil { | ||
log.SetOutput(xlog) | ||
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) // remove timestamp | ||
} | ||
} | ||
|
||
func writePidfile(pidfile string) { | ||
err := ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664) | ||
if err != nil { | ||
log.Output(1, "Unable to create pidfile "+pidfile) | ||
time.Sleep(20 * time.Second) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
//+build windows | ||
|
||
// Windows fake functions when editing on windows | ||
// -- this is intended to work on Unix first. | ||
package main | ||
|
||
type myXlog int | ||
|
||
var xlog myXlog | ||
|
||
func (myXlog) Err(string) {} | ||
func (myXlog) Info(string) {} | ||
func initSyslog(s string) {} | ||
func writePidfile(s string) {} | ||
//+BUILD WINDOWS | ||
|
||
// Windows fake functions when editing on windows | ||
// -- this is intended to work on Unix first. | ||
package main | ||
|
||
type myXlog int | ||
|
||
var xlog myXlog | ||
|
||
func (myXlog) Err(string) {} | ||
func (myXlog) Info(string) {} | ||
func initSyslog(s string) {} | ||
func writePidfile(s string) {} |
Oops, something went wrong.