Don’t use Golang

Golang is a trend now but there is a lot of projects where you have to avoid of using it.

Let’s start from what kind of benefits brings Golang for your team/project:

– Easy to learn and get started with. This helps to grow your team quickly and involve new people even without any experience with Golang.

– Built-in concurrency and a robust standard library. Which allows to utilise your CPU in the most effective way and easily create multithreading applications (channels, mutex, atomic etc.).

– Strict types helps to avoid some basic coding issues. So these options shows us that Golang is a good tool for high performance projects and big growing teams.

But otherwise when your team is small and you don’t need to solve high performance tasks. That means that you will have some troubles like a very big codebase.

– Lack of generics in Golang will make you to write / support more code.

– Writing of multithreading programms even in Golang requires to have senior engineers. So that means you will have to spend more money on your team without any incomes from using Golang.

– It will take more time to release because you will need to write/support a bigger codebase.


When you don’t need to use Golang in your team/project?

– Your project is not simple (it is not quite small like some CLI utilities or small service) and it should be build as a monolithic application with a small team

– Your budget is not big and you don’t have too much time for release

– Your project is new and you have to release it ASAP to make money

– You don’t have any high performance problems which can not be solved on your current technical stack

App build fail fix for session_srtp.go:144:9: assignment mismatch: 1 variable but h.Unmarshal returns 2 values

# github.com/pion/srtp/v2
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/session_srtp.go:144:9: assignment mismatch: 1 variable but h.Unmarshal returns 2 values
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp.go:37:9: assignment mismatch: 1 variable but header.Unmarshal returns 2 values
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp.go:52:9: assignment mismatch: 1 variable but header.Unmarshal returns 2 values
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp.go:56:51: header.PayloadOffset undefined (type *rtp.Header has no field or method PayloadOffset)
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp_cipher_aead_aes_gcm.go:99:13: header.PayloadOffset undefined (type *rtp.Header has no field or method PayloadOffset)
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp_cipher_aead_aes_gcm.go:104:18: header.PayloadOffset undefined (type *rtp.Header has no field or method PayloadOffset)
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp_cipher_aes_cm_hmac_sha1.go:121:30: header.PayloadOffset undefined (type *rtp.Header has no field or method PayloadOffset)
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/srtp_cipher_aes_cm_hmac_sha1.go:126:32: header.PayloadOffset undefined (type *rtp.Header has no field or method PayloadOffset)
../../../../1.16.2/pkg/mod/github.com/pion/srtp/v2@v2.0.2/stream_srtp.go:88:6: assignment mismatch: 1 variable but header.Unmarshal returns 2 values

While working on the one of my pet projects I caught the issue with building of my app. The fix is very easy but I spent some time to find out the issue and how to solve it.

So if you have the same issue you have to add to your go.mod file such line:

github.com/pion/srtp/v2 v2.0.5 // indirect

And update your packages with go mod. The problem was on this line – https://github.com/pion/srtp/compare/v2.0.4…v2.0.5#diff-42e63a61fe336233215c8623a90b1e1697a38e30aa9cafc1c396a9e37d61c00cR144

Golang library for MongoDB (DBAL)

Here is my DBAL implementation for mongoDB that I am using in my daily routines.

It contains features that I am using frequently it does not contain any implementation for DSL or Query Builders.

All extra features will be added later or maybe I will put it into a different library.

https://github.com/wajox/mongol

From Rails to KrakenD proxy: config generation for your routes

require "action_dispatch/routing/inspector"

begin
  namespace :krakend do
    task :routes => :environment do

      inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
      formatter = CustomRoutesFormatter.new
      routes_filter = {}

      puts inspector.format(formatter, routes_filter)
    end
  end
end

class CustomRoutesFormatter < ActionDispatch::Routing::ConsoleFormatter::Expanded
  def section_title(title)
  end

  def section(routes)
    @buffer << draw_expanded_section(routes)
  end

  private

  def draw_expanded_section(routes)
    routes.map.each_with_index do |r, i|
      path = r[:path].gsub("(.:format)", "").gsub(/:([a-z_]*)/, "{\\1}")

      <<~MESSAGE.chomp
        {
          "endpoint": "#{path}",
          "method": "#{r[:verb]}",
          "querystring_params": ["*"],
          "extra_config": {},
          "output_encoding": "no-op",
          "concurrent_calls": 1,
          "headers_to_pass": ["*"],
          "backend": [
            {
              "url_pattern": "#{path}",
              "encoding": "no-op",
              "extra_config": {},
              "sd": "static",
              "host": [
                "http://rails-app"
              ],
              "disable_host_sanitize": true
            }
          ]
        },
      MESSAGE
    end
  end
end

This approach can help you easily build krakend.json for your rails application.

GopherCon 2019

Побывали на Российской ГоферКонфе 🙂

Было очень полезно и интересно, очень понравились доклады от Konrad Reiche(go generate: One File to Rule Them All) и Денис Исаев(Линтеры в Go: как их готовить).

http://gophercon-russia.ru

Golang Hints: Create MongoDB Object ID from String

Sometimes you may want to find something by the Object ID in your MongoDB and due to you URI or query string contains ID you should convert the string ID to Object ID.

Below is a code that converts string ID to Object ID:

 package main

import (
"go.mongodb.org/mongo-driver/bson/primitive"
"fmt"
)
func main() {
oid, err := primitive.ObjectIDFromHex(recordID)

fmt.Printf("%s %v", err, oid)

  // if err := collection.FindOne(ctx, bson.M{"_id": oid}).Decode(e); err != nil {
  // return nil, err
// }
}

Presenting Go-Up

Today I have started development of new package for Golang-developers – Go-Up. I made it because I have noticed that I should repeat some things with each new project on Golang, so the main purpose of Go-Up package is to simplify building of new Golang applications.

This is a beginning so I just want to share link to GitHub here – https://github.com/ildarusmanov/go-up

KrakenD config example

What is KrakenD?

KrakenD is your self-designed REST API Gateway that feeds from your existing data services (Your APIs, legacy, cloud, IoT…) Just define visually or in a configuration file the endpoints your applications will use and the KrakenD will fetch and transform the content at your will for you.

https://www.krakend.io

Configuration example(proxy for POST, GET requests):

{
  "version": 2,
  "extra_config": {
    "github_com/devopsfaith/krakend-gologging": {
      "level": "WARNING",
      "prefix": "[KRAKEND]",
      "syslog": false,
      "stdout": true
    },
    "github_com/devopsfaith/krakend-metrics": {
      "collection_time": "60s",
      "proxy_disabled": false,
      "router_disabled": false,
      "backend_disabled": false,
      "endpoint_disabled": false,
      "listen_address": ":8090"
    },
    "github_com/devopsfaith/krakend-cors": {
      "allow_origins": [ "*" ],
      "allow_methods": [ "POST", "GET", "PUT", "DELETE" ],
      "allow_headers": [
        "Origin",
        "Authorization",
        "Content-Type",
        "Accept",
        "X-Auth-Token"
      ],
      "expose_headers": [ "Content-Length" ],
      "max_age": "12h"
    }
  },
  "timeout": "3000ms",
  "cache_ttl": "300s",
  "output_encoding": "no-op",
  "name": "api-proxy",
  "port": 80,
  "endpoints": [
    {
      "endpoint": "/",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "url_pattern": "/",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://some-landing"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
    {
      "method": "GET",
      "endpoint": "/api/v1/endpoint}",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "method": "POST",
          "url_pattern": "/api/v1/{endpoint}",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://backend-service-getter"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
    {
      "method": "POST",
      "endpoint": "/api/v1/endpoint}",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "method": "POST",
          "url_pattern": "/api/v1/{endpoint}",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://backend-service-poster"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
}