Game Changer: Introduction to Procyon (Part 1)

Burak Köken
4 min readDec 15, 2020

Hello everyone :) I had talked about Procyon briefly in my previous story. Today, We’re gonna talk about it in detail.

I think that Procyon could be a game changer. You will understand better why I think this way soon. Keep following my articles :)

Gopher Artwork

What is Procyon?

Procyon is an HTTP web framework written in Go, powered by fasthttp
and third-party libraries. If you need a comprehensive web framework, then I recommend you to use Procyon. Because it provides a lot of modules including several features.

  • It makes it easy to create production-grade applications.
  • It aims to ease to build, develop, and deploy your web applications quickly in Go.

Third-Party Libraries

We use some third-party libraries while developing Procyon. Here is the list we’ve used :

  • fasthttp, It is 10 times faster than the standard HTTP library.
  • jsoniter, It is used to encode and decode. It’s faster than the standard library.
  • logrus is a structured logger for Go, completely API compatible with the standard library logger.

Modules

There are several modules in the Procyon Framework :

  • procyon: It provides all features of Procyon.
  • procyon-core: This provides core features and utilities for all modules.
  • procyon-configure: This includes and provides configurations that configure the application automatically.
  • procyon-context: This provides context for Procyon applications.
  • procyon-web: It provides web support for developing web applications.
  • procyon-peas: This allows us to manage our instances created in the Procyon application. Peas are very similar to Java Beans. They can be called Go Beans :)

How to use Procyon?

It is so easy to use Procyon Framework. The only thing you have to do is to add the Procyon module into your go.mod and import it into your code file as follows.

main.go

Next, You need to invoke the method procyon.NewProcyonApplication to create a Procyon application in the main function.

Following, invoke the method Run to run the application.

Eventually, your code snippet will look like the following. It is easy that much to have a simple Procyon application.

After running, you will see the following console.

QuickStart

This part gives you a basic understanding of creating a simple endpoint and how to do it by using the Procyon Framework.

Components

Components are the part of Procyon Framework. Controller, Service, Repository, Initializers, etc. are considered as components.

Register Components

If you have a component like a Controller, you need to notify it Procyon as Go language doesn’t have an annotation like Java.

You don’t need to be worried about it. The only thing you have to do is to use the method core.Register in the method init as the following. It is provided by the module procyon-core.

Note that you have to give a function with only one return parameter, which will create an instance of the controller.

config.go

Our First Controller

The first thing you have to do to have a controller component in Procyon is to implement the interface Controller.

The interface Controller looks like the below. It is provided by the module procyon-web.

An example controller will look like the following. It might change based on your needs.

controller.go

Registry Handlers

Your handler registrations should be done by using the registry which will be passed into the method RegisterHandlers as you can see in the following code snippet.

You can see the complete code below. It is easy that much to create a controller and register your handlers.

Run Application

If you run your application without giving any parameter port, it will start on port 8080 as you can see in the following screenshot.

Running application

If you want to change the port on which the application starts, you can specify the parameter server.port.

When you specify the parameter port as 3030 (server.port=3030), your application will start on port 3030.

Request the endpoint

We assume that you have done all steps which need to be done and have a running application, then it’s time to request the endpoint /api/helloworld which we have created.

You can find the code on Github. And if you would like to contribute to the library or you find a bug, please report it.

I’m thinking of releasing its first stable version soon.

Gopher Artwork

Thanks for reading.

To be continued…

--

--