Ejemplo n.º 1
0
Archivo: ui.go Proyecto: kidaa/lantern
func init() {
	// Assume the default directory containing UI assets is
	// a sibling directory to this file's directory.
	localResourcesPath := ""
	_, curDir, _, ok := runtime.Caller(1)
	if !ok {
		log.Errorf("Unable to determine caller directory")
	} else {
		localResourcesPath = filepath.Join(curDir, LocalUIDir)
		absLocalResourcesPath, err := filepath.Abs(localResourcesPath)
		if err != nil {
			absLocalResourcesPath = localResourcesPath
		}
		log.Debugf("Creating tarfs filesystem that prefers local resources at %v", absLocalResourcesPath)
	}

	var err error
	fs, err = tarfs.New(Resources, localResourcesPath)
	if err != nil {
		// Panicking here because this shouldn't happen at runtime unless the
		// resources were incorrectly embedded.
		panic(fmt.Errorf("Unable to open tarfs filesystem: %v", err))
	}
	Translations = fs.SubDir("locale")
}
Ejemplo n.º 2
0
// MakeInitialConfig save baked-in config to the file specified by configPath
func MakeInitialConfig(configPath string) error {
	dir, _, err := bootstrapPath(lanternYamlName)
	if err != nil {
		log.Errorf("Could not get bootstrap path %v", err)
		return err
	}

	// We need to use tarfs here because the lantern.yaml needs to embedded
	// in the binary for auto-updates to work. We also want the flexibility,
	// however, to embed it in installers to change various settings.
	fs, err := tarfs.New(Resources, dir)
	if err != nil {
		log.Errorf("Could not read resources? %v", err)
		return err
	}

	// Get the yaml file from either the local file system or from an
	// embedded resource, but ignore local file system files if they're
	// empty.
	bytes, err := fs.GetIgnoreLocalEmpty("lantern.yaml")
	if err != nil {
		log.Errorf("Could not read bootstrap file %v", err)
		return err
	}
	err = ioutil.WriteFile(configPath, bytes, 0644)
	if err != nil {
		log.Errorf("Could not write bootstrap file %v", err)
		return err
	}
	return nil
}
Ejemplo n.º 3
0
Archivo: demo.go Proyecto: 2722/lantern
func main() {
	var fs http.FileSystem
	var err error
	fs, err = tarfs.New(Resources, "localresources")
	if err != nil {
		log.Fatal(err.Error())
	}
	http.Handle("/", http.FileServer(fs))
	log.Printf("About to listen at %v", addr)
	log.Printf("Try browsing to http://%v", addr)
	err = http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal(err.Error())
	}
}