This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"golang.org/x/exp/slog" | |
) | |
func main() { | |
jsonHandler := slog.NewJSONHandler(os.Stdout, nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mongo is a mongo implementation of the Customer Repository | |
package mongo | |
import ( | |
"context" | |
"time" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
"go.mongodb.org/mongo-driver/bson" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ValuesRequest struct { | |
Values []int `json:"values"` | |
} | |
func CalculateHighest(w http.ResponseWriter, r *http.Request) { | |
// Declare a valuerequest | |
var vr ValuesRequest | |
// Decode and respond with error incase it fails | |
err := json.NewDecoder(r.Body).Decode(&vr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------App.svelte-------- | |
<script> | |
import Header from './Header.svelte'; | |
</script> | |
<Header></Header> | |
<h1>Subtitle</h1> | |
<style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"time" | |
) | |
// Event is the Messages sent over the websocket | |
// Used to differ between different actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client is a websocket client, basically a frontend visitor | |
type Client struct { | |
// the websocket connection | |
connection *websocket.Conn | |
// manager is the manager used to manage the client | |
manager *Manager | |
// egress is used to avoid concurrent writes on the WebSocket | |
egress chan Event | |
// chatroom is used to know what room user is in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setupEventHandlers configures and adds all handlers | |
func (m *Manager) setupEventHandlers() { | |
m.handlers[EventSendMessage] = SendMessageHandler | |
m.handlers[EventChangeRoom] = ChatRoomHandler | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ChangeChatRoomEvent is used to switch chatroom | |
* */ | |
class ChangeChatRoomEvent { | |
constructor(name) { | |
this.name = name; | |
} | |
} | |
/** | |
* changeChatRoom will update the value of selectedchat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* routeEvent is a proxy function that routes | |
* events into their correct Handler | |
* based on the type field | |
* */ | |
function routeEvent(event) { | |
if (event.type === undefined) { | |
alert("no 'type' field in event"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* sendMessage will send a new message onto the Chat | |
* */ | |
function sendMessage() { | |
var newmessage = document.getElementById("message"); | |
if (newmessage != null) { | |
let outgoingEvent = new SendMessageEvent(newmessage.value, "percy"); | |
sendEvent("send_message", outgoingEvent) | |
} | |
return false; |
NewerOlder