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

frame/g 请问怎么拦截静态文件呢 #4167

Closed
weaweawe01 opened this issue Feb 24, 2025 · 4 comments
Closed

frame/g 请问怎么拦截静态文件呢 #4167

weaweawe01 opened this issue Feb 24, 2025 · 4 comments
Labels

Comments

@weaweawe01
Copy link

What do you want to ask?

全局中间件 中教程中有写到。 “全局中间件仅对动态请求拦截有效,无法拦截静态文件请求。”

我现在有个特殊的需求就是 需要在没有登录的情况下什么都访问不了。包括静态文件这种的怎么 操作呢

@Issues-translate-bot Issues-translate-bot changed the title frame/g 请问怎么才能拦截静态请求呢 frame/g How can I intercept static requests? Feb 24, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


What do you want to ask?

Global Middleware is written in the tutorial. "Global middleware is only valid for dynamic request interception, and cannot intercept static file requests."

I have a special need now, which is to have no access to anything without logging in. How to operate such as static files

@weaweawe01 weaweawe01 changed the title frame/g How can I intercept static requests? frame/g 请问怎么拦截静态文件呢 Feb 24, 2025
@wln32
Copy link
Member

wln32 commented Feb 25, 2025

@weaweawe01 可以尝试hook,示例如下

s.BindHookHandlerByMap("/static/*", map[ghttp.HookName]ghttp.HandlerFunc{
		ghttp.HookBeforeServe:  func(r *ghttp.Request) { fmt.Println(ghttp.HookBeforeServe) },
		ghttp.HookAfterServe:   func(r *ghttp.Request) { fmt.Println(ghttp.HookAfterServe) },
		ghttp.HookBeforeOutput: func(r *ghttp.Request) { fmt.Println(ghttp.HookBeforeOutput) },
		ghttp.HookAfterOutput:  func(r *ghttp.Request) { fmt.Println(ghttp.HookAfterOutput) },
	})

@weaweawe01
Copy link
Author

搞定

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Get it done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants