コード例 #1
0
ファイル: main.go プロジェクト: toyang/wide
// The only one init function in Wide.
func init() {
	confPath := flag.String("conf", "conf/wide.json", "path of wide.json")
	confIP := flag.String("ip", "", "this will overwrite Wide.IP if specified")
	confPort := flag.String("port", "", "this will overwrite Wide.Port if specified")
	confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
	confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel if specified")
	confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified")
	confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
	confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified")
	confStat := flag.Bool("stat", false, "whether report statistics periodically")
	confDocker := flag.Bool("docker", false, "whether run in a docker container")
	confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified")

	flag.Parse()

	log.SetLevel("warn")
	logger = log.NewLogger(os.Stdout)

	wd := util.OS.Pwd()
	if strings.HasPrefix(wd, os.TempDir()) {
		logger.Error("Don't run Wide in OS' temp directory or with `go run`")

		os.Exit(-1)
	}

	i18n.Load()

	event.Load()

	conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel,
		*confPlayground, *confDocker)

	conf.FixedTimeCheckEnv()

	session.FixedTimeSave()
	session.FixedTimeRelease()

	if *confStat {
		session.FixedTimeReport()
	}

	logger.Debug("host ["+runtime.Version()+", "+runtime.GOOS+"_"+runtime.GOARCH+"], cross-compilation ",
		util.Go.GetCrossPlatforms())
}
コード例 #2
0
ファイル: wide.go プロジェクト: nivance/wide
	StaticServer          string // static resources server scheme, host and port (http://{IP}:{Port})
	LogLevel              string // logging level: trace/debug/info/warn/error
	Channel               string // channel (ws://{IP}:{Port})
	HTTPSessionMaxAge     int    // HTTP session max age (in seciond)
	StaticResourceVersion string // version of static resources
	MaxProcs              int    // Go max procs
	RuntimeMode           string // runtime mode (dev/prod)
	WD                    string // current working direcitory, ${pwd}
	Locale                string // default locale
	Playground            string // playground directory
	AllowRegister         bool   // allow register or not
	Autocomplete          bool   // default autocomplete
}

// Logger.
var logger = log.NewLogger(os.Stdout)

// Wide configurations.
var Wide *conf

// configurations of users.
var Users []*User

// Indicates whether runs via Docker.
var Docker bool

// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
	confPlayground string, confDocker bool) {
	// XXX: ugly args list....
コード例 #3
0
ファイル: file.go プロジェクト: 29206394/wide
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
	"io"
	"os"
	"path/filepath"
	"strings"

	"github.com/b3log/wide/log"
)

// Logger.
var fileLogger = log.NewLogger(os.Stdout)

type myfile struct{}

// File utilities.
var File = myfile{}

// GetFileSize get the length in bytes of file of the specified path.
func (*myfile) GetFileSize(path string) int64 {
	fi, err := os.Stat(path)
	if nil != err {
		return -1
	}

	return fi.Size()
}
コード例 #4
0
ファイル: ret.go プロジェクト: toyang/wide
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
	"compress/gzip"
	"encoding/json"
	"net/http"
	"os"

	"github.com/b3log/wide/log"
)

// Logger.
var retLogger = log.NewLogger(os.Stdout)

// Result.
type Result struct {
	Succ bool        `json:"succ"` // successful or not
	Code string      `json:"code"` // return code
	Msg  string      `json:"msg"`  // message
	Data interface{} `json:"data"` // data object
}

// NewResult creates a result with Succ=true, Code="0", Msg="", Data=nil.
func NewResult() *Result {
	return &Result{
		Succ: true,
		Code: "0",
		Msg:  "",
コード例 #5
0
ファイル: conf.go プロジェクト: marswang/coditorx
func loadConf(confIP, confPort, confChannel string) {
	bytes, err := ioutil.ReadFile("conf/coditor.json")
	if nil != err {
		logger.Error(err)

		os.Exit(-1)
	}

	conf = &config{}

	err = json.Unmarshal(bytes, conf)
	if err != nil {
		logger.Error("Parses [coditor.json] error: ", err)

		os.Exit(-1)
	}

	log.SetLevel(conf.LogLevel)

	logger = log.NewLogger(os.Stdout)

	logger.Debug("Conf: \n" + string(bytes))

	// Working Driectory
	conf.WD = util.OS.Pwd()
	logger.Debugf("${pwd} [%s]", conf.WD)

	// IP
	ip, err := util.Net.LocalIP()
	if err != nil {
		logger.Error(err)

		os.Exit(-1)
	}

	logger.Debugf("${ip} [%s]", ip)

	conf.IP = strings.Replace(conf.IP, "${ip}", ip, 1)
	if "" != confIP {
		conf.IP = confIP
	}

	if "" != confPort {
		conf.Port = confPort
	}

	// Server
	conf.Server = strings.Replace(conf.Server, "{IP}", conf.IP, 1)

	// Static Server
	conf.StaticServer = strings.Replace(conf.StaticServer, "{IP}", conf.IP, 1)
	conf.StaticServer = strings.Replace(conf.StaticServer, "{Port}", conf.Port, 1)

	conf.StaticResourceVersion = strings.Replace(conf.StaticResourceVersion, "${time}", strconv.FormatInt(time.Now().UnixNano(), 10), 1)

	// Channel
	conf.Channel = strings.Replace(conf.Channel, "{IP}", conf.IP, 1)
	conf.Channel = strings.Replace(conf.Channel, "{Port}", conf.Port, 1)

	if "" != confChannel {
		conf.Channel = confChannel
	}

	conf.Server = strings.Replace(conf.Server, "{Port}", conf.Port, 1)

}