|
@@ -1,11 +1,64 @@
|
|
package web
|
|
package web
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "net/http"
|
|
|
|
+ "time"
|
|
|
|
+
|
|
"code.osinet.fr/fgm/kurz/domain"
|
|
"code.osinet.fr/fgm/kurz/domain"
|
|
"github.com/gorilla/mux"
|
|
"github.com/gorilla/mux"
|
|
- "net/http"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+
|
|
|
|
+Template variables:
|
|
|
|
+
|
|
|
|
+ - FullyQualifiedAssetsBaseURL http:
|
|
|
|
+ - FullyQualifiedShortURL (short string)
|
|
|
|
+ - FullyQualifiedSiteURL http:
|
|
|
|
+ - FullyQualifiedTargetURL (target string)
|
|
|
|
+ - RefreshDelay (seconds int)
|
|
|
|
+ - SiteName PlusVite
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+type bytes = []byte
|
|
|
|
+
|
|
|
|
+func build403(w http.ResponseWriter, short string) (bytes, error) {
|
|
|
|
+ type Short403Data struct {
|
|
|
|
+ FullyQualifiedAssetsBaseURL string
|
|
|
|
+ FullyQualifiedShortURL string
|
|
|
|
+ FullyQualifiedSiteURL string
|
|
|
|
+ RefreshDelay time.Duration
|
|
|
|
+ SiteName string
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ data := Short403Data{}
|
|
|
|
+ tmpl.Execute(w, data)
|
|
|
|
+ return bytes(""), nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func build404(w http.ResponseWriter, short string) (bytes, error) {
|
|
|
|
+ type Short404Data struct {
|
|
|
|
+ AssetsVersion int
|
|
|
|
+ FullyQualifiedAssetsBaseURL string
|
|
|
|
+ FullyQualifiedShortURL string
|
|
|
|
+ FullyQualifiedSiteURL string
|
|
|
|
+ FullyQualifiedTargetURL string
|
|
|
|
+ RefreshDelay time.Duration
|
|
|
|
+ SiteName string
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ data := Short404Data{}
|
|
|
|
+ err := tmpl.Execute(w, data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ }
|
|
|
|
+ return bytes(""), nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func build451(w http.ResponseWriter, short string) (bytes, error) {
|
|
|
|
+ return nil, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
func handleGetShort(w http.ResponseWriter, r *http.Request) {
|
|
func handleGetShort(w http.ResponseWriter, r *http.Request) {
|
|
short, ok := mux.Vars(r)["short"]
|
|
short, ok := mux.Vars(r)["short"]
|
|
@@ -36,14 +89,37 @@ func handleGetShort(w http.ResponseWriter, r *http.Request) {
|
|
switch domainErr.Kind {
|
|
switch domainErr.Kind {
|
|
case domain.ShortNotFound:
|
|
case domain.ShortNotFound:
|
|
status = http.StatusNotFound
|
|
status = http.StatusNotFound
|
|
|
|
+ if page, err := build404(w, short); err != nil {
|
|
|
|
+ status = http.StatusInternalServerError
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ } else {
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ w.Write(page)
|
|
|
|
+ }
|
|
|
|
+
|
|
case domain.TargetBlockedError:
|
|
case domain.TargetBlockedError:
|
|
status = http.StatusForbidden
|
|
status = http.StatusForbidden
|
|
|
|
+ if page, err := build403(w, short); err != nil {
|
|
|
|
+ status = http.StatusInternalServerError
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ } else {
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ w.Write(page)
|
|
|
|
+ }
|
|
|
|
+
|
|
case domain.TargetCensoredError:
|
|
case domain.TargetCensoredError:
|
|
status = http.StatusUnavailableForLegalReasons
|
|
status = http.StatusUnavailableForLegalReasons
|
|
|
|
+ if page, err := build451(w, short); err != nil {
|
|
|
|
+ status = http.StatusInternalServerError
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ } else {
|
|
|
|
+ w.WriteHeader(status)
|
|
|
|
+ w.Write(page)
|
|
|
|
+ }
|
|
|
|
+
|
|
default:
|
|
default:
|
|
|
|
|
|
status = http.StatusInternalServerError
|
|
status = http.StatusInternalServerError
|
|
|
|
+ w.WriteHeader(status)
|
|
}
|
|
}
|
|
-
|
|
|
|
- w.WriteHeader(status)
|
|
|
|
}
|
|
}
|