Example #1
0
func NewForwardInput(logger *logging.Logger, bind string, port Port) (*ForwardInput, error) {
	_codec := codec.MsgpackHandle{}
	_codec.MapType = reflect.TypeOf(map[string]interface{}(nil))
	_codec.RawToString = false
	addr, err := net.ResolveTCPAddr("tcp", bind)
	if err != nil {
		logger.Error("%s", err.Error())
		return nil, err
	}
	listener, err := net.ListenTCP("tcp", addr)
	if err != nil {
		logger.Error("%s", err.Error())
		return nil, err
	}
	return &ForwardInput{
		port:           port,
		logger:         logger,
		bind:           bind,
		listener:       listener,
		codec:          &_codec,
		clients:        make(map[*net.TCPConn]*forwardClient),
		clientsMtx:     sync.Mutex{},
		entries:        0,
		wg:             sync.WaitGroup{},
		acceptChan:     make(chan *net.TCPConn),
		shutdownChan:   make(chan struct{}),
		isShuttingDown: uintptr(0),
	}, nil
}
Example #2
0
File: git.go Project: pulcy/pulsar
// Execute a `git status a b`
func Diff(log *log.Logger, a, b string) (string, error) {
	args := []string{"diff",
		a,
		b,
	}
	if msg, err := util.Exec(log, cmdName, args...); err != nil {
		if log != nil {
			log.Error(msg)
		} else {
			fmt.Printf("%s\n", msg)
		}
		return "", maskAny(err)
	} else {
		return strings.TrimSpace(msg), nil
	}
}
Example #3
0
File: git.go Project: pulcy/pulsar
// Execute a `git status`
func Status(log *log.Logger, porcelain bool) (string, error) {
	args := []string{"status"}
	if porcelain {
		args = append(args, "--porcelain")
	}
	if msg, err := util.Exec(log, cmdName, args...); err != nil {
		if log != nil {
			log.Error(msg)
		} else {
			fmt.Printf("%s\n", msg)
		}
		return "", maskAny(err)
	} else {
		return strings.TrimSpace(msg), nil
	}
}
Example #4
0
File: init.go Project: pulcy/pulsar
func initGit(log *log.Logger, projectDir string) error {
	path := filepath.Join(projectDir, gitDirPath)
	if info, err := os.Stat(path); os.IsNotExist(err) {
		if err := util.ExecuteInDir(projectDir, func() error {
			output, err := util.Exec(log, "git", "init")
			if err != nil {
				log.Error(output)
				return maskAny(err)
			}
			return nil
		}); err != nil {
			return maskAny(err)
		}
	} else if err != nil {
		return maskAny(err)
	} else if !info.IsDir() {
		return maskAny(fmt.Errorf("%s must be a directory", path))
	} else {
		log.Debugf("Git already initialized in %s", projectDir)
	}
	return nil
}