Initial commit
This commit is contained in:
20
internal/README.md
Normal file
20
internal/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# `/internal`
|
||||
|
||||
Private application and library code. This is the code you don't want others importing in their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself. See the Go 1.4 [`release notes`](https://golang.org/doc/go1.4#internalpackages) for more details. Note that you are not limited to the top level `internal` directory. You can have more than one `internal` directory at any level of your project tree.
|
||||
|
||||
You can optionally add a bit of extra structure to your internal packages to separate your shared and non-shared internal code. It's not required (especially for smaller projects), but it's nice to have visual clues showing the intended package use. Your actual application code can go in the `/internal/app` directory (e.g., `/internal/app/myapp`) and the code shared by those apps in the `/internal/pkg` directory (e.g., `/internal/pkg/myprivlib`).
|
||||
|
||||
Examples:
|
||||
|
||||
* https://github.com/hashicorp/terraform/tree/main/internal
|
||||
* https://github.com/influxdata/influxdb/tree/master/internal
|
||||
* https://github.com/perkeep/perkeep/tree/master/internal
|
||||
* https://github.com/jaegertracing/jaeger/tree/main/internal
|
||||
* https://github.com/moby/moby/tree/master/internal
|
||||
* https://github.com/satellity/satellity/tree/main/internal
|
||||
|
||||
## `/internal/pkg`
|
||||
|
||||
Examples:
|
||||
|
||||
* https://github.com/hashicorp/waypoint/tree/main/internal/pkg
|
||||
0
internal/app/telal/.keep
Normal file
0
internal/app/telal/.keep
Normal file
55
internal/app/telal/adserver.go
Normal file
55
internal/app/telal/adserver.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package telal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Message represents the format of messages sent to clients
|
||||
type Message struct {
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func ServeAds() {
|
||||
// Create a new WebSocket upgrader
|
||||
upgrader := websocket.Upgrader{}
|
||||
|
||||
// Create a handler function for WebSocket connections
|
||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
// Upgrade the HTTP connection to a WebSocket connection
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Send a message containing an image URL every 5 seconds
|
||||
for {
|
||||
message := Message{
|
||||
Type: "image",
|
||||
URL: "http://example.com/image.jpg",
|
||||
}
|
||||
jsonMessage, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
err = conn.WriteMessage(websocket.TextMessage, jsonMessage)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
// Set up an HTTP server with the WebSocket handler
|
||||
http.HandleFunc("/", handler)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
0
internal/pkg/telalhtml/.keep
Normal file
0
internal/pkg/telalhtml/.keep
Normal file
Reference in New Issue
Block a user