Post

OAuth 2.0 Server & Authorization Middleware for Gin-Gonic

Project OAuth OAuth is an open source project developed in Go and available on GitHub .  The project offers an Authorization Server and an Authorization Middleware that can be used to make secure access to resources API and provide a simple and efficient implementation of the OAuth 2.0 specification. Authorization Server and Middleware are both based on Gin-Gonic and can interoperate with any other middleware available for this framework.  Authorization Server The Authorization Server is implemented by the struct OAuthBearerServer that manages two grant types of authorizations: password and client_credentials. This Authorization Server is made to provide authorization token usable for consuming resources API. Developers need only add their own implementation of CredentialsVerifier interface to validate the credentials of users or applications that require a token. package main import (  "errors"  "time"  "gopkg.in/gin-gonic/gin.v1"  &q

Data Model Generation for PostgreSQL

DinGo is a simple Go code generator that is useful to produce Microservice applications starting from the database schema. PostgreSQL supported As I showed in the previous post DinGo produces code reading the database schema and its first version supported only the MySQL database, but now after a not so short and unfortunately not continuous work, finally the PostgreSQL database has been supported. The current release (2.0.beta) contains all the templates and producers for providing microservices that can operate on Postgres. This DinGo release is still in beta because it requires a few tests and there are also some limitations. Postgres array types are not supported and I don't know if they will be in the future. Reading the Information Schema PostgreSQL offers two methods for retrieving meta-data about the table's schema using the system catalogs ( pg_class, pg_user, pg_view, ...) or querying the information_schema (available since Postgres 7.4). DinGo has

From the database schema to RESTful API with DinGo

Immagine
In the  previous post I had started writing about data model and code generation and the post coincided with the boot of an open source project called DinGo thought to generate the Go code for a Microservice host analysing the schema of a relational database. It's a very SQL First approach to write code, so I don't think it should be good for all the projects, but surely there are many applications that can take advantage from this, at least those are using already defined relational databases and want to adopt a Microservice architecture and RESTful API. What DinGo does DinGo creates a Microservice application starting from a MySQL database schema. Dingo follows these steps during the generation process: DinGo reads the information_schema of the MySQL database it generates a set of Data Model structs used to map tables into Go structs it generates the Data Access Objects , these objects provide a set of basic operations (CRUD operations) necessary to manipulat

Data Model Code Generation

Don't repeat yourself Often developing applications we find ourselves writing the same code more than once and often this code regards access to data. If the data are stored on the relational database we need to implement the functions that perform the operations of create, read, update and delete (CRUD) and some other utility functions  to retrieve a entity by  primary key, count the entities in the table and etc. We can write the same code for each entity or we can write the code generator that will implement it for us. For this reason code generators can be useful to produce the repetitive code that we should implement by hand, thus eliminating the tedious part of writing code. Querying MySQL Information_Schema In order to generate the code that accesses the entities we need to know the structure of these entities. If the data are stored on the MySQL database we can query the " Information Schema " to know the database structure. Information_schema contain

OVO Key/Value Storage

Yet another Key/Value Storage ? I started developing OVO , my own implementation of a Key/Value Storage, six month ago because I wanted to test developing a project using the Go language. In the past , I had already worked on a similar project , GetCache , but it is developed with .Net framework . I don't think that the world lacks the Key / Value Storage , but for me it is treated to a great gym to train my Go . I have r ealized that this project with the Go language is extraordinarily simple and so I would like to share this experience. What is OVO Initially, the project aimed to create a distributed cache , like Memcached , that would allow to store  objects  and   JSON   structures  quickly by spreading the load across multiple servers , and could run on any kind of Linux , Windows , iOS machine . Each cached object can have a time-to-live property ( TTL) set so that the removal is done automatically when it expires. Then