Sample code snippet to familiarize golang . Concept of goroutines , channels, concurrency is implemented in a sample scenario

go-mysql-goroutines-channel

Sample code snippet to familiarize golang . Concept of goroutines , channels, concurrency , interface, slice, error handling, Blank Identifier etc is implemented in a sample scenario

Preface

This repository is the sample of web application using golang. This code snippet used mysql as DBMS , GORM as ORM and .tmpl extension in frontend (go template file)

Install

Perform the following steps:

  1. Download and install Golang - https://go.dev/ .
  2. go get gorm.io/driver/mysql
  3. go get -u gorm.io/gorm

NB: Please refer https://gorm.io/ before installing the ORM packages

WorkFlow

  • This application has a basic interface Event which has 2 abstract functions All(), New()

  • 2 structures are defined (Encounter, AuditLog). The models Encounter, AuditLog implements methods of the event interface.

  • There is a form to add bulk data

  • in main package there is 2 goroutines defined

     *  poolDataToChannel -  To pool the bulk data into a channel
    
     *  insertDataFromPool -  To insert data into encounter , audit log from the channel   
    
  • When the form is filled and submitted 2 goroutines run concurrenlty ie.. fetching and insertion is done concorrently

Run the application

_> cd gosampleportal

gosampleportal _> run go . (in windows)

gosampleportal _> run go *.go (in linux)

Sample console output

D:\code\gosampleportal>go run .

Userid - 1 , Location - john location added to channel

Userid - 1 , Location - john location . Inserted to encounter

Userid - 1 , Location - john location Logtype - Portal , Module - Calendar. Inserted to Audit Log

Userid - 2 , Location - joe location added to channel

Userid - 2 , Location - joe location . Inserted to encounter

Userid - 2 , Location - joe location Logtype - Portal , Module - Calendar. Inserted to Audit Log

Userid - 3 , Location - jane location added to channel

Userid - 3 , Location - jane location . Inserted to encounter

Userid - 3 , Location - jane location Logtype - Portal , Module - Calendar. Inserted to Audit Log

concurrency vs parallelism

If there’s one thing most people know about Go, is that it is designed for concurrency. No introduction to Go is complete without a demonstration of its goroutines and channels.

But when people hear the word concurrency they often think of parallelism, a related but quite distinct concept. In programming, concurrency is the composition of independently executing processes, while parallelism is the simultaneous execution of (possibly related) computations. Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.

https://go.dev/blog/waza-talk

Similar Resources

golang orm

korm golang orm, 一个简单易用的orm, 支持嵌套事务 安装 go get github.com/wdaglb/korm go get github.com/go-sql-driver/mysql 支持数据库 mysql https://github.com/go-sql-driv

Oct 31, 2022

Golang ORM with focus on PostgreSQL features and performance

go-pg is in a maintenance mode and only critical issues are addressed. New development happens in Bun repo which offers similar functionality but works with PostgreSQL, MySQL, and SQLite.

Jan 8, 2023

Very simple example of golang buffalo CRUD

Buffalo CRUD exemple Introduction Site du projet : https://gobuffalo.io/fr Documentation générale : https://gobuffalo.io/fr/docs/overview/ Documentati

Nov 7, 2021

The fantastic ORM library for Golang, aims to be developer friendly

GORM The fantastic ORM library for Golang, aims to be developer friendly. Overview Full-Featured ORM Associations (Has One, Has Many, Belongs To, Many

Nov 11, 2021

SQL mapper ORM framework for Golang

 SQL mapper ORM framework for Golang

SQL mapper ORM framework for Golang English 中文 Please read the documentation website carefully when using the tutorial. DOC Powerful Features High Per

Dec 8, 2021

Automatically generate tags for golang struct.

gtag is a command tool that can automatically generate tags for golang struct. Quick start Install gtag into your GOPATH go install github.com/sycki/g

Feb 12, 2022

Golang mysql orm, a personal learning project, dedicated to easy use of mysql

golang mysql orm 个人学习项目, 一个易于使用的mysql-orm mapping struct to mysql table golang结构

Dec 30, 2021

Go-mysql-orm - Golang mysql orm,dedicated to easy use of mysql

golang mysql orm 个人学习项目, 一个易于使用的mysql-orm mapping struct to mysql table golang结构

Jan 7, 2023

Mybatis for golang - SQL mapper ORM framework

SQL mapper ORM framework for Golang English 中文 Please read the documentation website carefully when using the tutorial. DOC Powerful Features High Per

Nov 10, 2022
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.

go-queryset 100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood. Contents

Dec 30, 2022
A better ORM for Go, based on non-empty interfaces and code generation.

reform A better ORM for Go and database/sql. It uses non-empty interfaces, code generation (go generate), and initialization-time reflection as oppose

Dec 31, 2022
A better ORM for Go, based on non-empty interfaces and code generation.
A better ORM for Go, based on non-empty interfaces and code generation.

A better ORM for Go and database/sql. It uses non-empty interfaces, code generation (go generate), and initialization-time reflection as opposed to interface{}, type system sidestepping, and runtime reflection. It will be kept simple.

Dec 29, 2022
A code generator base on GORM

GORM/GEN The code generator base on GORM, aims to be developer friendly. Overview CRUD or DIY query method code generation Auto migration from databas

Jan 1, 2023
Code that will query the meta data of an instance within AWS and provide a json formatted output on Go

EC2 meta-data, output JSON Code that will query the meta data of an instance wit

Dec 16, 2021
Crud - A mysql crud code generate tool from table DDL sql file

crud is a mysql crud code generate tool 中文文档 Getting Started Overview Crud is a

Oct 13, 2022
Golang struct-to-table database mapper

Structable: Struct-Table Mapping for Go Warning: This is the Structable 4 development branch. For a stable release, use version 3.1.0. Structable deve

Dec 27, 2022
A pure golang SQL database for learning database theory

Go SQL DB 中文 "Go SQL DB" is a relational database that supports SQL queries for research purposes. The main goal is to show the basic principles and k

Dec 29, 2022
Golang Object Graph Mapper for Neo4j

GoGM Golang Object Graph Mapper v2 go get -u github.com/mindstand/gogm/v2 Features Struct Mapping through the gogm struct decorator Full support for

Dec 28, 2022
An orm library support nGQL for Golang

norm An ORM library support nGQL for Golang. Overview Build insert nGQL by struct / map (Support vertex, edge). Parse Nebula execute result to struct

Dec 1, 2022