Exemplo n.º 1
0
Arquivo: iris.go Projeto: toksea/iris
// StaticServe serves a directory as web resource
// it's the simpliest form of the Static* functions
// Almost same usage as StaticWeb
// accepts only one required parameter which is the systemPath ( the same path will be used to register the GET&HEAD routes)
// if second parameter is empty, otherwise the requestPath is the second parameter
// it uses gzip compression (compression on each request, no file cache)
func (api *muxAPI) StaticServe(systemPath string, requestPath ...string) RouteNameFunc {
	var reqPath string

	if len(requestPath) == 0 {
		reqPath = strings.Replace(systemPath, utils.PathSeparator, slash, -1) // replaces any \ to /
		reqPath = strings.Replace(reqPath, "//", slash, -1)                   // for any case, replaces // to /
		reqPath = strings.Replace(reqPath, ".", "", -1)                       // replace any dots (./mypath -> /mypath)
	} else {
		reqPath = requestPath[0]
	}

	return api.Get(reqPath+"/*file", func(ctx *Context) {
		filepath := ctx.Param("file")

		spath := strings.Replace(filepath, "/", utils.PathSeparator, -1)
		spath = path.Join(systemPath, spath)

		if !utils.DirectoryExists(spath) {
			ctx.NotFound()
			return
		}

		ctx.ServeFile(spath, true)
	})
}
Exemplo n.º 2
0
Arquivo: create.go Projeto: RR1007/new
func create(flags cli.Flags) (err error) {

	targetDir, err := filepath.Abs(flags.String("dir"))
	if err != nil {
		panic(err)
	}

	if !isValidInstallDir(targetDir) {
		printer.Dangerf("\nPlease make sure you are targeting a directory inside $GOPATH, type iris -h for help.")
		return
	}

	if !utils.DirectoryExists(packagesInstallDir) || !flags.Bool("offline") {
		downloadPackages()
	}

	createPackage(flags.String("type"), targetDir)
	return
}
Exemplo n.º 3
0
func create(flags cli.Flags) (err error) {

	if !utils.DirectoryExists(packagesInstallDir) || !flags.Bool("offline") {
		downloadPackages()
	}

	targetDir := flags.String("dir")

	// remove first and last / if any
	if strings.HasPrefix(targetDir, "./") || strings.HasPrefix(targetDir, "."+utils.PathSeparator) {
		targetDir = targetDir[2:]
	}
	if targetDir[len(targetDir)-1] == '/' {
		targetDir = targetDir[0 : len(targetDir)-1]
	}
	//

	createPackage(flags.String("type"), targetDir)
	return
}
Exemplo n.º 4
0
func create(flags cli.Flags) (err error) {

	targetDir, err := filepath.Abs(flags.String("dir"))
	if err != nil {
		panic(err)
	}

	if !isValidInstallDir(targetDir) {
		printer.Dangerf("\nPlease make sure you are targeting a directory inside $GOPATH, type iris -h for help.")
		return
	}

	if !utils.DirectoryExists(packagesInstallDir) || !flags.Bool("offline") {
		// install/update go dependencies at the same time downloading the zip from the github iris-contrib assets
		finish := make(chan bool)
		go func() {
			go func() {
				for _, source := range packagesDependencies {
					gogetCmd := utils.CommandBuilder("go", "get", source)
					if msg, err := gogetCmd.CombinedOutput(); err != nil {
						panic("Unable to go get " + source + " please make sure you're connected to the internet.\nSolution: Remove your $GOPATH/src/github.com/iris-contrib/middleware folder and re-run the iris create\nReason:\n" + string(msg))
					}
				}
				finish <- true

			}()

			downloadPackages()
			<-finish
		}()

		<-finish
		close(finish)
	}
	createPackage(flags.String("type"), targetDir)
	return
}
Exemplo n.º 5
0
// DirectoryExists returns true if a given local directory exists
func (d *pluginDownloadManager) DirectoryExists(dir string) bool {
	return utils.DirectoryExists(dir)
}