package binding import "strings" // Static 静态绑定 // 参数: // - binder: 用来执行绑定的binder // - item: 执行绑定的参数 func Static(binder *Binder, item *StaticBindItem) { item.bind(binder) } // StaticFile 静态文件绑定 // 参数: // - binder: 用来执行绑定的binder // - item: 执行绑定的参数 func StaticFile(binder *Binder, item *StaticFileBindItem) { item.bind(binder) } // StaticBindItem 静态BindItem type StaticBindItem struct { // 创建的静态绑定API的URL相对路径 RelativePath string // 目录的根路径 Root string // 传递的RelativePath是否包含了路由的BasePath WithBasePath bool } func (item *StaticBindItem) bind(binder *Binder) { if item.WithBasePath { binder.router.Static(strings.TrimPrefix(item.RelativePath, binder.router.BasePath()), item.Root) } else { binder.router.Static(item.RelativePath, item.Root) } } // StaticFileBindItem 静态文件BindItem type StaticFileBindItem struct { // 创建的静态绑定API的URL相对路径 RelativePath string // 文件路径 FilePath string // 传递的RelativePath是否包含了路由的BasePath WithBasePath bool } func (item *StaticFileBindItem) bind(binder *Binder) { if item.WithBasePath { binder.router.StaticFile(strings.TrimPrefix(item.RelativePath, binder.router.BasePath()), item.FilePath) } else { binder.router.StaticFile(item.RelativePath, item.FilePath) } }