shared project

This commit is contained in:
geek 2017-04-13 19:51:48 +09:00
commit 1ddc196741
7 changed files with 213 additions and 0 deletions

63
.gitignore vendored Normal file
View File

@ -0,0 +1,63 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.idea/
.idea/libraries/

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="Go SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../../1.8/src" />
</CLASSES>
<SOURCES>
<root url="file://$PROJECT_DIR$/../../../../../1.8/src" />
</SOURCES>
</library>
</component>

97
config.go Normal file
View File

@ -0,0 +1,97 @@
package config_manager_go
import (
"os"
"log"
"io/ioutil"
"loafle.com/overflow/crawler_go/config"
"encoding/json"
"strings"
)
const (
OVERFLOW_CONFIG_PATH = "/Overflow/Config"
)
type ConfigManager struct {
}
func (config *ConfigManager) readByTempConfig(c *config.Config) (error) {
pwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
b, err := ioutil.ReadFile(pwd+"/example.json")
err = json.Unmarshal(b,&c)
return err
}
func (config *ConfigManager) writeConfig(c config.Config) (error){
var fileName = c.Id
fileJson, _ := json.Marshal(c)
path, _ := config.getFilePath(c)
err := ioutil.WriteFile(path + "/" + fileName + ".json", fileJson, 0644)
return err
}
func (config *ConfigManager) getFilePath(c config.Config) (string, error){
var parentPath string = strings.Join(configSettingFolder,"")
cctmp := c.Crawler.Container
cctmps := strings.Split(cctmp,"_")
containerPath := cctmps[0]
cns := strings.Split(c.Crawler.Name, "_")
cn := cns[0]
rs := parentPath + OVERFLOW_CONFIG_PATH +"/"+containerPath+"/"+cn
err := checkFolder(rs)
return rs, err
}
func checkFolder(path string) (error) {
_, err := os.Stat(path)
if err != nil {
log.Println(err)
}
if os.IsNotExist(err) {
os.MkdirAll(path, os.ModePerm)
}
return nil
}
func Start(b []byte) {
// config json stream read
// config json byte read
var err error
cm := ConfigManager{}
c := config.Config{}
if len(b) == 0 || b == nil {
err = cm.readByTempConfig(&c)
} else {
err = json.Unmarshal(b, &c)
}
if err != nil {
log.Fatal(err)
}
cm.writeConfig(c)
}
// config json save folder
// create folder for config
// config json parse

6
config_darwin.go Normal file
View File

@ -0,0 +1,6 @@
package config_manager_go
import "os"
var hasVendorName = true
var configSettingFolder = []string{os.Getenv("/etc/overflow/config")}

8
config_test.go Normal file
View File

@ -0,0 +1,8 @@
package config_manager_go
import "testing"
func TestStart(t *testing.T) {
Start(nil)
}

6
config_windows.go Normal file
View File

@ -0,0 +1,6 @@
package config_manager_go
import "os"
var hasVendorName = true
var configSettingFolder = []string{os.Getenv("PROGRAMDATA")}

23
example.json Normal file
View File

@ -0,0 +1,23 @@
{
"id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734",
"target" : {
"connection" : {
"ip" : "192.168.1.104",
"port" : "6379",
"ssl" : false,
"portType" : "tcp"
},
"auth" : {
}
},
"schedule" : {
"interval" : "10"
},
"crawler" : {
"name":"redis_protocol_crawler",
"container":"network_crawler"
},
"items" : [
]
}