Exemple #1
0
func Open(config config.Config, index *lsmtree.Index) (*Store, error) {
	path := config.GetString("store.path")
	dirPerm := config.GetIntString("store.dir_permissions")
	filePerm := config.GetIntString("store.file_permissions")
	s := Store{path, os.FileMode(dirPerm), os.FileMode(filePerm), index}

	if err := os.MkdirAll(s.crapPath(), s.dirPerm); err != nil {
		return nil, err
	}
	if err := util.CreateLockFile(s.lockPath(), s.filePerm); err != nil {
		return nil, err
	}

	if err := s.initStore(); err != nil {
		return nil, err
	}

	return &s, nil
}
Exemple #2
0
func Listen(config config.Config, store *store.Store) (net.Listener, error) {
	lis, err := net.Listen("tcp", config.GetString("network.listen_address"))
	if err != nil {
		return nil, err
	}

	go func() {
		for {
			sock, err := lis.Accept()
			if err != nil {
				panic(err)
			}

			conn := newConn(store, sock)
			go conn.handleConnection()
		}
	}()

	return lis, nil
}