Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/perbu/go-sqlite-http

non-oo reference http impl
https://github.com/perbu/go-sqlite-http

Last synced: about 2 months ago
JSON representation

non-oo reference http impl

Awesome Lists containing this project

README

        

# Non-OO servers in Go

## Typical Go server

```go

package main

import (
"fmt"
"golang.org/x/tools/go/types/typeutil"
"net/http"
)

type Server struct {
dependency database.Connection
}

func NewServer(dep database.Connection) *Server {
return &Server{dependency: dep}
}

func (s *Server) RootHandler(w http.ResponseWriter, r *http.Request) {
// do something with s.dependency:
s.dependency.Query("SELECT * FROM users")
fmt.Fprintf(w, "Hello, Users!")
}

func main() {
dep := database.NewConnection()
s := NewServer(dep)
http.HandleFunc("/", s.RootHandler)
http.ListenAndServe(":8080", nil)
}

```