Giter VIP home page Giter VIP logo

example-golang's Introduction

Hi there, ๐Ÿ‘‹๐Ÿผ ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

May we leave a world better than the one we found!! ๐ŸŒŽ๐Ÿƒโ˜€๏ธ

I'm a software engineer with a passion for technology and where we got to with it...

Current Languages and Tools:

DevOps โค๏ธ:

Languages and tools worked these years:

  • ๐Ÿ”ญ โš›๏ธ I created a social project (Religare App) to help people with depression or personal problems anonymously, with solutions and emotional intelligence...
  • ๐Ÿ’ผ I worked for more than 10 years with national scale systems for the Brazilian government and I already worked as a software engineer for Philips in the Tasy system and other companies...
  • โณ I created an google chrome extension to help us focus on tasks and know our time on the job Planus...
  • ๐Ÿ“‹ I create a open sourcer platform for agile development j3scrum.com...
  • ๐ŸŒฑ Iโ€™m currently learning Elixir and Go ...

Site โ€ข Medium โ€ข Twitter โ€ข Religare App โ€ข j3scrum โ€ข Planus

example-golang's People

Contributors

ruyjfs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

example-golang's Issues

Database connection at each request.

type Service struct {

}

func (m *Service) Db() *gorm.DB {
	return config.Db()
}

The code above adds a utility function to quickly access config.Db()
But the function config.Db() creates a new connection each time with the code below:

func Db() *gorm.DB {
	dsn := fmt.Sprintf(
		"host=%s port=%s dbname=%s user=%s password=%s sslmode=disable TimeZone=%s",
		os.Getenv("DB_HOST"),
		os.Getenv("DB_PORT"),
		os.Getenv("DB_NAME"),
		os.Getenv("DB_USER"),
		os.Getenv("DB_PASSWORD"),
		os.Getenv("DB_TIMEZONE"),
	)

	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	return db
}

That means each request to the HTTP server will re-create the database connection. I wonder if this is something you made on purpose or you missed this point. I am a newbie at go-lang so I'd like to know.

Thanks for this inspiring project.

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.