package binding import "strings" func Static(binder *Binder, item *StaticBindItem) { item.bind(binder) } func StaticFile(binder *Binder, item *StaticFileBindItem) { item.bind(binder) } // StaticBindItem 静态路由item type StaticBindItem struct { RelativePath string Root string 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) } } type StaticFileBindItem struct { RelativePath string FilePath string 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) } }