Skip to content

Commit f8dfbb4

Browse files
committed
Move redirect code into sub package
Signed-off-by: Adam Reese <[email protected]>
1 parent 1c51c0e commit f8dfbb4

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/fermyon/spin-redirect
22

33
go 1.24
44

5-
require github.com/fermyon/spin/sdk/go v1.4.2
5+
require github.com/spinframework/spin-go-sdk v0.0.0-20250310233821-2665ad7e30a4
66

77
require github.com/julienschmidt/httprouter v1.3.0 // indirect
8+
9+
replace github.com/spinframework/spin-go-sdk => github.com/fermyon/spin-go-sdk v0.0.0-20250310233821-2665ad7e30a4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github.com/fermyon/spin/sdk/go v1.4.2 h1:4U2J2WooKptCa4zeBetKctz/DEJxv3RvGauW0bZ+e6U=
2-
github.com/fermyon/spin/sdk/go v1.4.2/go.mod h1:yb8lGesopgj/GwPzLPATxcOeqWZT/HjrzEFfwbztAXE=
1+
github.com/fermyon/spin-go-sdk v0.0.0-20250310233821-2665ad7e30a4 h1:er/5jOnjXEjx95+7iiioj5l/CwT5AQgM7Udr8xM/mDI=
2+
github.com/fermyon/spin-go-sdk v0.0.0-20250310233821-2665ad7e30a4/go.mod h1:9GoW1+MR0gN1OEinITtjPOzmu0dur3U6ty3pIH/gN24=
33
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
44
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
spinhttp "github.com/spinframework/spin-go-sdk/http"
5+
6+
"github.com/fermyon/spin-redirect/redirect"
7+
)
8+
9+
func init() {
10+
r := redirect.NewSpinRedirect()
11+
spinhttp.Handle(r.HandleFunc)
12+
}
13+
14+
func main() {
15+
}

config.go renamed to redirect/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package main
1+
package redirect
22

33
import (
44
"os"
55
"strings"
66

7-
config "github.com/fermyon/spin/sdk/go/config"
7+
config "github.com/spinframework/spin-go-sdk/variables"
88
)
99

1010
type ConfigReader interface {

redirect.go renamed to redirect/redirect.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package main
1+
package redirect
22

33
import (
44
"net/http"
55
"net/url"
66
"path"
77
"strconv"
88
"strings"
9-
10-
spinhttp "github.com/fermyon/spin/sdk/go/http"
119
)
1210

1311
const (
@@ -25,14 +23,6 @@ const (
2523
trimPrefixKey string = "trim_prefix"
2624
)
2725

28-
func init() {
29-
r := NewSpinRedirect()
30-
spinhttp.Handle(r.handleFunc)
31-
}
32-
33-
func main() {
34-
}
35-
3626
// SpinRedirect is a struct that provides a handleFunc
3727
// for redirecting to a destination URL using configurable HTTP status code.
3828
type SpinRedirect struct {
@@ -46,7 +36,7 @@ func NewSpinRedirect() SpinRedirect {
4636
}
4737
}
4838

49-
func (s SpinRedirect) handleFunc(w http.ResponseWriter, r *http.Request) {
39+
func (s SpinRedirect) HandleFunc(w http.ResponseWriter, r *http.Request) {
5040
dest, _ := s.getDestination()
5141
code, _ := s.getStatusCode(r.Method)
5242

redirect/redirect_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package redirect

0 commit comments

Comments
 (0)