Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/murymi/trygo
trying go
https://github.com/murymi/trygo
Last synced: 7 days ago
JSON representation
trying go
- Host: GitHub
- URL: https://github.com/murymi/trygo
- Owner: murymi
- Created: 2024-06-07T12:28:17.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-06-08T21:56:35.000Z (5 months ago)
- Last Synced: 2024-07-23T23:36:45.306Z (4 months ago)
- Language: Go
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
#### server
```go
package mainimport (
"fmt"
"io"
"net""github.com/wojciechmurimi/trygo"
)func main() {
var l, err = net.Listen("tcp", ":3000")
if err != nil {
panic("failed to create tcp listener")
}var server = trygo.CreateHTTPServer(l)
for {
request, err := server.Accept()
if err != nil {
panic("failed to accept a new connection")
}
fmt.Println("a new connection has been accepted")
var buff [1024]byte
for !request.Finished() {
_, e := request.Read(buff[:])
if e != nil {
if e != io.EOF {
panic(e)
}
break
}
}
var response trygo.ResponseBuilder
response.SetCode(200).SetHeader("done", "yes")
request.Write([]byte(response.String()))
request.Close()
}
}
```#### client
```go
package mainimport (
"fmt"
"io""github.com/wojciechmurimi/trygo"
)func main() {
var client trygo.HTTPClient
resp, err := client.Connect("https://internet.org")
if err != nil {
fmt.Println(err);
panic("failed to connect")
}
var buff [1024]byte
for !resp.Finished() {
r, e := resp.Read(buff[:])
if e != nil {
if e != io.EOF {
panic(e)
}
break
}
fmt.Println(string(buff[:r]))
}
}
```