-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to integrate pkger for embeded resources? #1575
Comments
Of coruse it can @tuhao1020 Actually, it's easy the app := iris.New()
// ...
app.HandleDir("/", pkger.Dir("./public")) However as I can see, this library converts the files on-fly(?), the files should be available in your current directory. Iris can do it using the app.HandleDir("/", iris.Dir("./public"), iris.DirOptions{
Cache: iris.DirCacheOptions{
Enable:true,
},
}) If they have an option for embedded files (no need of physical files to be exist in the drive for a file-server) then you can just pass their Indeed, Iris provides even more features here, take a look the full options of type DirCacheOptions struct {
// Enable or disable cache.
Enable bool
// Minimum content size for compression in bytes.
CompressMinSize int64
// Ignore compress files that match this pattern.
CompressIgnore *regexp.Regexp
// The available sever's encodings to be negotiated with the client's needs,
// common values: gzip, br.
Encodings []string
// If greater than zero then prints information about cached files to the stdout.
// If it's 1 then it prints only the total cached and after-compression reduced file sizes
// If it's 2 then it prints it per file too.
Verbose uint8
} If you need embedded assets as Go source code, you may want to use Thanks. |
thanks for your relpy! the second parameter of app.HandleDir is
everything seems ok, but resources in Compare the usage of Gin with pkger:
the second parameter of router.StaticFs is do you consider adding a method that accept a |
Hello @tuhao1020, you are not watching me. You don't use the $ cd your_project
$ go get -u github.com/kataras/iris/v12@master
$ go run . Now, are you ready for a real comparison? gin: router := gin.New()
router.StaticFs("/", pkger.Dir("/public"))
router.Run(":8080") That's all, you cannot customize it further. iris: app := iris.New()
app.HandleDir("/", pkger.Dir("/public"))
app.Listen(":8080")
// DirListFunc is the function signature for customizing directory and file listing.
// See `DirList` and `DirListRich` functions for its implementations.
type DirListFunc func(ctx *context.Context, dirOptions DirOptions, dirName string, dir http.File) error
// Attachments options for files to be downloaded and saved locally by the client.
// See `DirOptions`.
type Attachments struct {
// Set to true to enable the files to be downloaded and
// saved locally by the client, instead of serving the file.
Enable bool
// Options to send files with a limit of bytes sent per second.
Limit float64
Burst int
// Use this function to change the sent filename.
NameFunc func(systemName string) (attachmentName string)
}
// DirCacheOptions holds the options for the cached file system.
// See `DirOptions`structure for more.
type DirCacheOptions struct {
// Enable or disable cache.
Enable bool
// Minimum content size for compression in bytes.
CompressMinSize int64
// Ignore compress files that match this pattern.
CompressIgnore *regexp.Regexp
// The available sever's encodings to be negotiated with the client's needs,
// common values: gzip, br.
Encodings []string
// If greater than zero then prints information about cached files to the stdout.
// If it's 1 then it prints only the total cached and after-compression reduced file sizes
// If it's 2 then it prints it per file too.
Verbose uint8
}
// DirOptions contains the settings that `FileServer` can use to serve files.
// See `DefaultDirOptions`.
type DirOptions struct {
// Defaults to "/index.html", if request path is ending with **/*/$IndexName
// then it redirects to **/*(/) which another handler is handling it,
// that another handler, called index handler, is auto-registered by the framework
// if end developer does not managed to handle it by hand.
IndexName string
// PushTargets filenames (map's value) to
// be served without additional client's requests (HTTP/2 Push)
// when a specific request path (map's key WITHOUT prefix)
// is requested and it's not a directory (it's an `IndexFile`).
//
// Example:
// "/": {
// "favicon.ico",
// "js/main.js",
// "css/main.css",
// }
PushTargets map[string][]string
// PushTargetsRegexp like `PushTargets` but accepts regexp which
// is compared against all files under a directory (recursively).
// The `IndexName` should be set.
//
// Example:
// "/": regexp.MustCompile("((.*).js|(.*).css|(.*).ico)$")
// See `iris.MatchCommonAssets` too.
PushTargetsRegexp map[string]*regexp.Regexp
// Cache to enable in-memory cache and pre-compress files.
Cache DirCacheOptions
// When files should served under compression.
Compress bool
// List the files inside the current requested directory if `IndexName` not found.
ShowList bool
// If `ShowList` is true then this function will be used instead
// of the default one to show the list of files of a current requested directory(dir).
// See `DirListRich` package-level function too.
DirList DirListFunc
// Files downloaded and saved locally.
Attachments Attachments
// Optional validator that loops through each requested resource.
AssetValidator func(ctx *context.Context, name string) bool
} Have fun :) |
I got master branch and |
No worries @tuhao1020, I was thinking about it too but when you use templates inside bindata you usually have more data than the template files, or the bindata.go file may contain more templates that should be rendered using different parsers and engines. So, the |
All my projects use pkger to package static resources, so I prefer to use a On the other hand, |
Indeed you can convert anything to |
I got it, thank you! @kataras |
#1575 Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
@tuhao1020 It's done, now you can pass |
pkger is a tool for embedding static files into Go binaries. It can integrate with Gin, but I dont know how to integrate with Iris. If possible, can you give some example code?
The text was updated successfully, but these errors were encountered: