Skip to content

Commit

Permalink
simplify using cm3.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelcmtd committed Mar 27, 2023
1 parent 5eb592a commit b83eb3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/chrissxMedia/redirector

go 1.16

require github.com/prometheus/client_golang v1.14.0
require (
github.com/chrissxMedia/cm3.go v0.0.0-20230327023026-5b09b3e68183
github.com/prometheus/client_golang v1.14.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chrissxMedia/cm3.go v0.0.0-20230327023026-5b09b3e68183 h1:DRQfmnf1lS/K5wn+wrbTtSLJhyt6B9Pmcs4dQRD/1Ys=
github.com/chrissxMedia/cm3.go v0.0.0-20230327023026-5b09b3e68183/go.mod h1:f7SWla9HMSV27sT1HLXvwp52PvQTZOeNpWhJiI22Apk=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down
8 changes: 3 additions & 5 deletions redirector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
_ "embed"
"fmt"
"log"
"net/http"
"net/url"
"strings"

"github.com/chrissxMedia/cm3.go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand All @@ -30,9 +30,7 @@ func main() {
prometheus.MustRegister(hostReqs)
http.Handle("/metrics", promhttp.Handler())

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s request from %s: %s (%s)",
r.Proto, r.RemoteAddr, r.URL, r.Host)
cm3.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
totalReqs.WithLabelValues().Inc()
if strings.Contains(r.Host, ".") && !strings.Contains(r.Host, ":") {
var url = url.URL{Host: r.Host, Scheme: "https", Path: r.URL.Path}
Expand All @@ -43,5 +41,5 @@ func main() {
fmt.Fprintf(w, response)
})

http.ListenAndServe(":80", nil)
cm3.ListenAndServeHttp(":80", nil)
}

0 comments on commit b83eb3c

Please sign in to comment.