Skip to content

Instantly share code, notes, and snippets.

@bmorphism
Last active April 14, 2022 22:57
Show Gist options
  • Save bmorphism/ef1611f41146d28bc94134a1b758fe87 to your computer and use it in GitHub Desktop.
Save bmorphism/ef1611f41146d28bc94134a1b758fe87 to your computer and use it in GitHub Desktop.
hello-matrix.go
// Copyright 2077 securityDAO
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [START cloudrun_matrix_pilled_service]
// [START run_matrix_pilled_service]
// Verify Element homeserver domain using Google's knative fork
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
log.Print("Bobby!")
http.HandleFunc("/", handler)
http.HandleFunc("/.well-known/matrix/server", elementServer)
http.HandleFunc("/.well-known/matrix/client", elementClient)
// Determine port for HTTP service.
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("defaulting to port %s", port)
}
// Start HTTP server.
log.Printf("listening on port %s", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
name := os.Getenv("NAME")
if name == "" {
name = "mooncop"
}
fmt.Fprintf(w, "gm, %s!\n", name)
}
func elementClient(w http.ResponseWriter, r *http.Request) {
// return JSON proof
fmt.Fprintf(w, `{"m.server": "secdao.ems.host:443"}`)
}
func elementServer(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
fmt.Fprintf(w, `{"m.homeserver": {"base_url": "https://secdao.ems.host"}, "m.identity_server": {"base_url": "https://vector.im"}}`)
}
// [END run_matrix_pilled_service]
// [END cloudrun_matrix_pilled_service]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment