Skip to content
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

feat: add StaticFileFS #2749

Merged
merged 3 commits into from
Mar 18, 2022
Merged

feat: add StaticFileFS #2749

merged 3 commits into from
Mar 18, 2022

Conversation

thinkgos
Copy link
Contributor

@thinkgos thinkgos commented Jun 8, 2021

I was miising feature of Serving file form http.FileSystem
there has StaticFile,Static,StaticFS method, since go1.16 embed feature, I am not find how to get a file from embed fs. follow is my want

//go:embed mypic.png
var pic embed.FS

func main() {
	r := gin.Default()
        r.StaticFileFS("/alias_pic.png", "mypic.png", http.FS(pic))
        
	err := r.Run(":9000")
	if err != nil {
		panic(err)
	}
}

Use cases:
- Serve file by alias from http.FileSystem

@codecov
Copy link

codecov bot commented Jun 8, 2021

Codecov Report

Merging #2749 (2a24581) into master (34ce210) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2749      +/-   ##
==========================================
+ Coverage   98.69%   98.75%   +0.06%     
==========================================
  Files          41       41              
  Lines        2072     3064     +992     
==========================================
+ Hits         2045     3026     +981     
- Misses         15       26      +11     
  Partials       12       12              
Flag Coverage Δ
go-1.13 98.75% <100.00%> (?)
go-1.14 98.59% <100.00%> (?)
go-1.15 98.59% <100.00%> (?)
go-1.16 98.59% <100.00%> (?)
macos-latest 98.75% <100.00%> (?)
nomsgpack 98.74% <100.00%> (?)
ubuntu-latest 98.75% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
routergroup.go 100.00% <100.00%> (ø)
render/json.go 84.04% <0.00%> (-1.26%) ⬇️
gin.go 99.09% <0.00%> (-0.09%) ⬇️
utils.go 96.80% <0.00%> (-0.02%) ⬇️
fs.go 100.00% <0.00%> (ø)
auth.go 100.00% <0.00%> (ø)
mode.go 100.00% <0.00%> (ø)
path.go 100.00% <0.00%> (ø)
tree.go 100.00% <0.00%> (ø)
debug.go 100.00% <0.00%> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34ce210...2a24581. Read the comment docs.

daheige
daheige previously approved these changes Jun 26, 2021
README.md Outdated Show resolved Hide resolved
@thinkerou thinkerou added this to the v1.8 milestone Aug 22, 2021
improve StaticFile and StaticFileFS code, use staticFileHandler
@codenoid
Copy link
Contributor

any update?

@appleboy
Copy link
Member

@thinkerou Please help to review.

Copy link
Member

@thinkerou thinkerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@thinkerou thinkerou merged commit 417b142 into gin-gonic:master Mar 18, 2022
thinkerou added a commit that referenced this pull request Mar 18, 2022
daheige pushed a commit to daheige/gin that referenced this pull request Apr 18, 2022
* RouterGroup.StaticFileFS added
add StaticFileFS ad README

* fix Static content mistake

* update README `tab`
improve StaticFile and StaticFileFS code, use staticFileHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants