当前位置:网站首页>Gin blog summary 1
Gin blog summary 1
2022-06-10 14:12:00 【tnan2522】
gin It's based on go http The one enclosed on the package web frame , Blog dome Exhibition www.tnan.top/blog/
template function
stay gin Chinese can also be like jinja2 equally , Custom template function , It is mainly used to encapsulate templates Operations on template variables , For example, add two template variables , Template variable string cutting and other operations
app := gin.Default()
// Add a custom template function
app.SetFuncMap(template.FuncMap{
"stringadd": uitls.StringAdd,
"timecut": uitls.TimeCut,
"safe": uitls.Safe,
"truestring": uitls.TrueString,
"urladd": uitls.UrlAdd,
})
stay gin If HTML The data when rendering is HTML Label data , Then it treats the data as a string , Will be used in these data " " Rendering , And that's where it comes in template Medium template.HTML There's a transformation , because gin There is no such thing as jinja2 Template engine safe function , therefore , You can customize a safe template function
Customize 404 Processing function
stay web In development ,404 Is a common problem , When there is a 404 when ,gin Default will return 404 page not found
This return page is not very nice , We can use NoRoute
app := gin.Default()
// Customize 404 Processing function
app.NoRoute(controllers.NoResponse)
Custom processing returns 404 function
register HTML and css Static file path, etc
// register html Catalog
app := gin.Default()
app.LoadHTMLGlob("templates/*") // I'll find it from the current path templates Folder
// Register static resource directory
app.Static("static", "./static")
In the processing function return Time meeting from LoadHTMLGlob Find... Under the registered path html file , Such as

here ,details.html Will go to the registration path to find
Static files static app.Static("static", "./static") first static Yes, when static The initial request is treated as Request to get static file , first static You can view it as Path request api , the second ./static Is where to get the static file when it is requested ,./static Is under the current path static Catalog
边栏推荐
- 2022 practice questions and online simulation test for the third batch of Guangdong Provincial Safety Officer a certificate (principal)
- How to build Haojing technology when the computing power network is brought into reality?
- Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
- [advanced MySQL] optimize SQL by using the execution plan explain (2)
- Is it safe to open an account in qiniu
- About native SQL and database methods in PHP framework
- Operation of simulated examination platform for theoretical question bank of refrigeration and air conditioning equipment operation in 2022
- Gree mobile phone challenge Apple mobile phone? I'm afraid there's nothing else but hard talk
- Markdown Title centered
- UE5如何将屏幕坐标转为世界坐标和世界方向
猜你喜欢

Singleton pattern and special class design

CVPR 2022 | 基于序列对比学习的长视频逐帧动作表示

2022年制冷与空调设备运行操作理论题库模拟考试平台操作
![[cloud computing] what is the relationship between a multi cloud management platform and a public cloud?](/img/8f/f57da7079979ceaef903255bc25432.png)
[cloud computing] what is the relationship between a multi cloud management platform and a public cloud?
![[note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use](/img/b4/f7838a7e12379190e2bc9b869839f0.png)
[note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use
![[discrete mathematics review series] III. concept and operation of sets](/img/b5/5c7d077490875dbe0ff4777f6b0a7a.png)
[discrete mathematics review series] III. concept and operation of sets

技术分享| 快对讲,全球对讲

Anaconda installs opencv (CV2) and uses it in the jupyter notebook

Allan方差与随机误差辨识
![[FAQ] résumé des problèmes courants et des solutions lors de l'utilisation de l'interface API rest du Service de santé sportive](/img/ff/96a0a77795b271bef3a8ade2d646c3.png)
[FAQ] résumé des problèmes courants et des solutions lors de l'utilisation de l'interface API rest du Service de santé sportive
随机推荐
net core天马行空系列-可用于依赖注入的,数据库表和c#实体类互相转换的接口实现
Leetcode 829. Sum of continuous integers
2022危险化学品经营单位主要负责人考试题库及在线模拟考试
Primary master-slave table integration process development process
Adding, deleting, modifying and querying databases with JDBC
IIC总线的主要特点/通信过程/读写过程
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
2022年制冷与空调设备运行操作理论题库模拟考试平台操作
【离散数学期复习系列】一、命题逻辑
[discrete mathematics review series] i. propositional logic
The interview at the big factory was held at 10:00 a.m. and came out at 10:09 a.m. the question was really too
Gorm设置外键
2022 high frequency software test interview questions of large factories (with answers)
技术分享| 快对讲,全球对讲
Allan方差与随机误差辨识
Flutter Icon Stack LIsttitle...学习总结3
【离散数学期复习系列】三、集合的概念及运算
[discrete mathematics review series] III. concept and operation of sets
[discrete mathematics review series] VI. tree
大厂面试上午10:00面试,10:09就出来了 ,问的实在是太...