Browse Source

兼容前缀

lxg 3 years ago
parent
commit
e7750b71da
1 changed files with 4 additions and 0 deletions
  1. 4 0
      options.go

+ 4 - 0
options.go

@@ -3,6 +3,7 @@ package rest
 import (
 	"git.nspix.com/golang/micro/gateway/http"
 	"gorm.io/gorm"
+	"strings"
 )
 
 type Options struct {
@@ -17,6 +18,9 @@ type Option func(o *Options)
 
 func WithPrefix(prefix string) Option {
 	return func(o *Options) {
+		if !strings.HasPrefix(prefix, "/") {
+			prefix = "/" + prefix
+		}
 		o.Prefix = prefix
 	}
 }