Giter VIP home page Giter VIP logo

tada's Introduction

DEMO FOR A BIGGER PROJECT

I did this to help me visualize the ideas i had for a bigger project. I had this structure of an http server in mind but had to test it out to see how it will work out before starting the project.

The code is structured in a way to help me start new servers with little effort. If I decide to use microservice architecture, i would just turn the whole thing into a package that i can use to spring up new http servers with very little effort.

The most important types in this app are;

type server struct {
	router   *mux.Router
	httpSrv  *http.Server
	logger   *log.Logger
	
	// most api's have versioning in the form of /api/v1/something. I call the '/api/v1' the 
	// versionPrefix because it will be prefixed on the url of a route type. I wanted to
	// have that in the server and the best way I could achieve that was using a map to
	// keep track of a versionPrefix and the slice of routes that version
	// is released with. So I can initialize the routes by adding the versionPrefix to every
	// every url in the route associated with it.
	versions map[string][]route

	c        chan os.Signal // used to recieve interrupt signals to gracefully shutdown server.
}

and the

type route struct {
	url        string
	methods     []string
	controller func(http.ResponseWriter, *http.Request)
}

I'm thinking of making the controller accept context so its type declaration will change to something like func(context.Context) func(http.ResponseWriter, *http.Request), but i'm still struggling with the whole idea of the context package soo i'll hold off the idea for a bit. Ohhh, *http.Request already has context.Context type on it so making the controller accept additional context.Context will be a stupid thing to do.

Still thinking about how the database interfacing is going to be like. Arggh thats the hardest part for me right now since i have very little experience with databases. I haven't fully decided on whether to use an orm or go with the database/sql libary.

Might fuck around and make this whole thing into a package I can use to spawn http servers fast. But i won't like to use the same logic in multiple projects since i'll have to learn other ways of doing this kinda stuff.

tada's People

Contributors

joe-degs avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.