How I Structure New Projects In Golang

Anthony GG
3 Oct 202321:31

Summary

TLDR本视频由一位创业者讲述,他介绍了他的公司Laue近期开始进行的2.0版本重写过程。他解释了原项目是用Next.js和TypeScript编写的,但由于公司规模和项目范围的显著变化,他们决定将后端改写为使用Go语言,前端使用SvelteKit。视频中详细讨论了Go项目结构的设置,强调没有绝对的项目结构模式,而是应根据项目需求灵活调整。他还提到了如何处理数据库、业务逻辑、以及如何通过简化的方法有效地管理代码。此外,他鼓励开发者拥有结果驱动的开发心态,并提供了关于如何组织代码、选择框架和处理性能考虑的实用建议。

Takeaways

  • 😊没有绝对完美的项目结构,选择什么结构要根据自身团队需求决定
  • 👍使用 make 构建命令非常简单实用
  • 💡把逻辑分别放到 handlers、packages、data 等文件夹中可以很好地组织代码
  • 📁利用 types 文件夹存储共享的类型定义
  • 🔨利用 util 文件夹存储公共的工具函数
  • ⚙️handlers 只关注请求处理,业务逻辑放到 packages
  • 📦data 文件夹处理所有数据库相关逻辑
  • 🌈不必局限于后端或前端开发者的身份,要学会全栈思维
  • ✅测试业务逻辑用单元测试,测试数据逻辑用集成测试
  • ☝️简单的结构容易扩展,要用结果导向的方式迭代改进

Q & A

  • Laue公司是什么时候成立的?

    -Laue公司是三年前成立的。

  • 为什么Laue公司决定进行2.0版本的重写?

    -因为Laue公司最近获得了大量资金,且项目范围发生了显著变化,需要扩大规模。

  • Laue 2.0版本后端和前端分别采用了哪些技术?

    -后端采用Go语言编写,前端使用SvelteKit。

  • 视频中提到的'CMD文件夹'在Go项目结构中起什么作用?

    -CMD文件夹包含独立的包,每个包中都有一个main.go文件,用于引导不同的应用程序,比如API服务。

  • 为什么作者认为在编程中没有完美的项目结构?

    -因为编程领域中,很多人会强加他们创建的编程范式,认为它是最好的。但实际上,每种方法都有其好处和不足,应根据具体情况灵活调整。

  • 在Go项目中,作者如何看待性能问题?

    -作者认为,性能在大多数情况下不应该是主要关注点,因为在达到性能瓶颈之前,项目通常会有很大的用户基础,届时解决性能问题是可行的。

  • 什么是'result driven development mindset',作者为什么推荐它?

    -结果驱动开发心态意味着专注于实现目标和结果,而不是过分关注使用的工具和包的组织方式。作者推荐它,因为它鼓励开发人员根据实际情况灵活调整,专注于产出。

  • 视频中提到使用什么工具管理数据库迁移?

    -作者提到使用了一个简单的脚本来管理数据库迁移,尤其是在开发过程中处理数据库处于“脏状态”的情况。

  • 为什么作者提倡在开发中避免过度使用第三方CLI包?

    -作者认为使用简单脚本可以有效地完成任务,而不需要引入可能复杂和过度的第三方CLI包,从而保持项目的简洁性。

  • 在讨论Go项目结构时,作者如何处理全局变量的使用?

    -虽然全局变量在某些情况下可能带来风险,但作者认为,如果在正确的时间和地点使用,全局变量是可以接受的。尤其是在数据库实例的上下文中,全局变量可以简化数据访问。

Outlines

00:00

🚀 介绍Laue 2.0版本更新与技术选型

视频开始介绍了Laue公司及其背后的创立故事,并宣布了因获得大量资金投入和项目范围的显著变化,决定对项目进行重写,升级到2.0版本。新的技术栈选择了Go语言作为后端开发语言,前端则转向使用SvelteKit。视频中还承诺展示Go项目的结构设置,因为这是观众经常询问的问题。此外,作者鼓励观众订阅频道,点赞视频,留下评论,并加入他的Discord服务器和Patreon页面,以便获取更多学习资源和课程折扣。

05:02

📁 探索Go项目结构与开发策略

本段落深入探讨了Go项目的文件结构安排,强调在编程领域不存在完美的项目结构,而是应依据项目的具体需求灵活调整。作者提倡结果驱动的开发思维,鼓励开发者追随直觉进行项目结构的设计和调整。具体到项目结构,介绍了二进制文件存放的`bin`文件夹,以及包含主要启动文件的`CMD`文件夹。此外,强调了选择框架(如Echo、Gin等)的灵活性,以及性能问题通常不应成为早期开发的焦点。

10:02

🔧 简化CLI命令与数据库迁移策略

在这一部分,作者讨论了他对CLI工具包的使用方法,偏爱简单直接的脚本来处理数据库迁移和数据填充,而非复杂的CLI工具包。通过实例解释了`drop`命令的用途——解决数据库迁移中遇到的问题,以及如何通过`make`命令来执行数据库操作。这些操作展示了作者对于工具和技术选择的实用主义态度,即选择适合自己当前需求和方便的工具,而不是追求技术上的完美。

15:03

📚 数据管理与全局变量的合理应用

讨论了在项目中管理数据和使用全局变量的策略。作者首先解释了`DB`包的作用,它用于初始化数据库连接,并介绍了为何选择使用`bun`作为数据库交互工具。尽管存在类型安全的担忧,但作者强调了`bun`的实用性。此外,提到了全局变量的使用,虽然它在某些情况下被视为不佳的实践,但在恰当的场景下可以简化开发。数据层(Data)的设计重点在于集中处理数据交互逻辑,而不是混入其他逻辑。

20:04

🌐 处理请求与业务逻辑分离

这一段落深入介绍了如何处理网络请求和组织业务逻辑。通过举例说明了如何使用Go的新特性来创建中间件和处理函数,进而实现请求的处理。作者解释了在Leue项目中如何根据不同的用户角色(比如买方和卖方)来分组处理请求,并使用中间件进行权限控制。这体现了对代码组织和权限管理的深思熟虑,旨在提高代码的可维护性和安全性。

🔨 业务逻辑、类型定义与工具函数

最后一段深入讨论了项目中业务逻辑、类型定义和工具函数的组织。业务逻辑被放在`package`文件夹中,以区分简单的CRUD操作和需要复杂处理的业务场景。`types`文件夹用于存放项目中的共享类型和常量,以便在不同的包之间使用。`util`文件夹包含了一些辅助函数和工具,用于简化常见任务。作者还提到了保持开发者技能的全面性,鼓励不仅仅局限于前端或后端开发,而是成为能够解决问题的程序员。

Mindmap

Keywords

💡Laue 2.0

Laue 2.0代表视频中提到的一个重大更新和转型项目。原本的项目使用Next.js和TypeScript开发,但由于获得了大量资金支持和项目范围的显著变化,团队决定使用Golang重写后端,并采用SvelteKit作为前端技术栈。这一变化旨在提升项目的可扩展性和性能,反映了技术选型随着项目需求和环境的变化而变化的实际情况。

💡Golang

Golang是一个开源的编程语言,由Google开发,专注于简洁、高效和安全。视频中提到,团队选择Golang重写后端,主要是因为它的性能和适合于大规模系统的特性。Golang在项目结构组织和并发处理方面有独特的优势,这与视频中讨论的项目结构设置直接相关。

💡SvelteKit

SvelteKit是一个基于Svelte的框架,用于构建更高效的web应用程序。视频中提到,为了前端开发,团队决定采用SvelteKit替换原有的Next.js。这一决策体现了团队对于前端技术趋势的关注以及追求更好用户体验和开发效率的目标。

💡项目结构

项目结构是指如何组织代码文件和目录的方式。视频强调没有所谓的'完美'项目结构,而是应根据项目的具体需求和团队偏好来决定。视频中提供的结构示例包括了bin目录、CMD目录、data目录等,展示了一种针对Golang项目的组织方式,旨在提高代码的可维护性和扩展性。

💡Echo框架

Echo是一个高性能的Go web框架,提供了简洁的API来创建RESTful服务。视频中提到,尽管有多种框架可供选择,但他们选择了Echo来作为API的基础,这说明了在技术选型时,团队更倾向于选择能够满足项目需求且团队熟悉的技术。

💡性能

在视频中,性能被提到是在选择技术和框架时的一个考虑因素,但不是最关键的。视频中指出,除非应用达到了非常大的用户规模,性能才会成为瓶颈。这表明对于大多数项目而言,开发效率、易用性和可维护性可能是更重要的考量因素。

💡全局变量

全局变量在视频中被提及作为数据库连接实例的一种实现方式。尽管全局变量在某些情况下可能导致问题,但视频中认为如果在正确的时间和地点使用,它们是可以接受的。这一点反映了在设计软件架构时需要权衡不同方案的利弊。

💡单元测试与集成测试

视频中讨论了单元测试和集成测试在软件开发过程中的应用。尤其是提到对数据库交互的测试更适合通过集成测试而非单元测试来执行。这体现了测试策略应根据测试目标和项目需求灵活调整的原则。

💡业务逻辑

业务逻辑是指驱动应用程序行为的底层逻辑,通常反映了实际世界中业务操作的规则。视频中提到,某些功能可能直接与数据库交互,而不涉及复杂的业务逻辑,而更复杂的功能则需要在'package'目录下进行更深入的业务逻辑处理。这强调了根据功能的复杂性来组织代码的重要性。

💡前后端开发

视频最后讨论了前后端开发的界限,强调开发人员不应仅限于一个领域,而是应该具备解决问题的能力,无论是在前端还是后端。这表明在当今多变的技术环境中,成为一名全栈开发人员越来越重要。

Highlights

没有完美的项目结构,只有适合你和你团队的结构

追寻好的感觉,而不是被方法论束缚

性能不是重点,真正重要的是用户体验

使用全局变量可以很方便,但需要权衡利弊

数据相关逻辑都放在data包中

handlers只包含处理请求的简单函数

业务逻辑放在package包中

types包用于共享的类型和常量

util用于一些通用的小帮助函数

cmd包用于编译二进制文件

Makefile用于自动化调试和部署流程

整个项目结构足够灵活扩展

不要局限于某一类开发者,学会全栈

简单开始,需要时再引入更复杂的架构

满足需求才是成功与否的标准

Transcripts

play00:00

so we're recently starting to rewrite

play00:02

leue into the 2.0 version for the people

play00:05

I don't know what laue is it's a company

play00:07

I created three years ago and the

play00:09

original project was basically written

play00:10

in next GS everything in typescript

play00:13

which worked very well but right now we

play00:15

received a big amount of funding and the

play00:17

scope is changed dramatically so it's

play00:20

time to scale up and we decided to write

play00:23

the back end in goaling and use spelt

play00:27

kit as the front end right so uh and in

play00:30

this video I'm going to show you how we

play00:31

set up our gooling project structure

play00:33

because it's still a question that comes

play00:35

up a lot like Hey how do you structure

play00:37

gooling projects and before we continue

play00:40

if you like the videos that I'm

play00:41

providing to you please consider

play00:42

subscribing give me a thumbs up leave

play00:44

some questions in the comments and jump

play00:46

into the 4,000 people big Discord server

play00:50

where we learn from each other each and

play00:52

every single day and for the people that

play00:53

want to level up I also have the

play00:55

full-time GF course which is 50% off

play00:57

right now for a limited amount of time

play00:59

and I also have my patreon page so check

play01:01

these things out if you want to learn

play01:03

more about goang so before we actually

play01:07

continue with the folder structure here

play01:08

you can already see it on the left side

play01:11

of my screen there is no such thing as

play01:15

the perfect project structure or the

play01:17

good project structure or something that

play01:19

is good something that is wrong I think

play01:21

that doesn't exist in programming uh

play01:24

space I think a lot of people are

play01:25

forcing paradigms to you because they

play01:27

created that Paradigm and they want to

play01:29

Market it so we cannot blame them right

play01:32

if you make something you're probably

play01:33

going to Advocate that it's going to be

play01:35

the best thing because it sols a lot of

play01:37

problems and maybe it will right but

play01:40

whatever you do in life there's always

play01:41

some it's always going to give you

play01:43

benefits but it always also going to

play01:45

give you some uh negative Parts also

play01:48

that's something you need to keep in

play01:49

mind right um so if you have the if you

play01:52

have the possibility to start from

play01:57

scratch you actually never know what

play01:59

what's going to be the best thing you

play02:01

can have something in your mind like

play02:03

okay if we do it like this and and and

play02:04

these are the Futures we need this is

play02:06

probably something we're going to

play02:07

utilize in the future maybe we should do

play02:09

it this way most of the time it's going

play02:11

to change dramatically over time right

play02:13

it's going it's never going to stick

play02:15

like you like you originally planned it

play02:17

right so that's something you need to

play02:19

take in consideration and that's why I

play02:21

think everybody needs to have a more

play02:23

result driven development mindset which

play02:26

is basically instead of being confused

play02:29

about oh the tools and packages and ways

play02:32

to organize stuff I think you just need

play02:35

to go and Chase your good feeling what

play02:39

feels right what feels sus what feels

play02:43

good you know what I mean and change it

play02:45

along the way I think and just focus on

play02:47

the results instead of on um the way you

play02:51

program stuff right all right cool uh so

play02:54

basically how do we do these things well

play02:55

it's very simple uh we have um goang

play02:59

project here

play03:00

and first of all we have this bin folder

play03:02

here and this bin folder is basically

play03:03

just uh a folder where we are dumping in

play03:06

our binaries right uh and these binaries

play03:09

they are coming from the CMD folder

play03:11

right you can see there is no main. go

play03:13

in the rout right that's because we

play03:15

using this pattern it's it's a very

play03:18

common thing where you have these um

play03:20

separate packages right and each of

play03:23

these packages they have a main. go file

play03:25

here you can see that right and in this

play03:27

main.go we basically bootstrap um or API

play03:31

which is an

play03:32

echo project right uh it's using the

play03:35

echo framework so what framework do you

play03:37

need to use actually guys it does not

play03:39

really matter right you can use gen

play03:41

fiber Echo gorilla you can use the

play03:43

standard Library it doesn't really

play03:45

matter right people say yeah you don't

play03:46

need to use that or you need to use this

play03:48

it doesn't matter it really doesn't

play03:50

matter they all do the same things and

play03:51

they will all get you the same result

play03:54

right that's that's that's the reality

play03:57

right uh and you could say performance

play03:59

performance doesn't matter right again

play04:01

people are going to be very very

play04:04

confused and angry about the comment I

play04:06

say like performance doesn't matter like

play04:08

if per maybe performance will matter at

play04:10

a certain point of time and if

play04:13

performance is a

play04:15

bottleneck then I'm going to say

play04:17

congratulations to you because you

play04:19

actually makes made something that has

play04:22

some traction that that's a big traction

play04:24

because before you go to be in a

play04:26

performance bottleneck you're going to

play04:28

have a very very very very large user

play04:30

base and that's a luxury problem and

play04:33

that's going to be solved at the time

play04:36

it's going to be there right uh which in

play04:38

your case most of the time will never be

play04:40

right so performance is not something uh

play04:43

especially in goling with echoin you

play04:45

will you cannot go wrong it it it has a

play04:47

good performance don't worry about that

play04:49

guys don't worry about about about these

play04:51

paradigms uh about that fugazi right so

play04:54

we have this main thing which basically

play04:55

boots up um our API server and all that

play04:58

stuff right then we're going to have

play04:59

some other things so what I like to do

play05:01

um which is a little bit weird a lot of

play05:04

people use some kind of um CLI package I

play05:07

think I don't know maybe Viper or

play05:08

something I have no clue I never use

play05:10

these things and with the CLI package

play05:12

you can write all these commands and

play05:13

then you can execute them based on the

play05:15

user input but what I like to do is very

play05:17

lazy and very simple is just make um for

play05:21

example this drop thingy here right

play05:23

which basically drops all our accounts

play05:25

and why do I have this because um in our

play05:28

migration sometimes you can do make down

play05:30

for example which will um migrate will

play05:34

will

play05:35

will use all the down migration you know

play05:37

what I mean delete these tables but

play05:39

sometimes you're going to end up in a

play05:40

dirty State and then it it basically is

play05:43

going to refuse to uh drop your tables

play05:46

right make down is not going to work

play05:48

it's going to say yo your database is in

play05:49

a dirty state of course in production

play05:52

that's a good thing that that happens

play05:54

right uh but in development it's

play05:55

sometimes it's nasty because you have in

play05:57

a dirty State and you need to force do

play05:58

that stuff uh you need to force drop and

play06:01

sometimes you need to manually delete

play06:02

some tables and it's just a pain and

play06:04

yeah so I made this very dirty simple

play06:06

script it basically just deletes the

play06:09

whole shebang even the

play06:10

migrations uh and then we can just do a

play06:13

makeup again

play06:15

um and it's all good right that's this

play06:17

drop and the same thing with migrate you

play06:19

can see that basic um with this other

play06:21

thing here for for example the seat it

play06:23

basically go it's a dirty script that

play06:24

seeds some stuff into the database um

play06:26

just for yeah testing purposes right if

play06:28

you want to test your front end uh you

play06:30

just dump some some some seats uh into

play06:33

into your database um so you can see

play06:35

this all very simple scripts and the way

play06:38

we actually trigger them is in our make

play06:39

file you can see uh for example make

play06:42

down it just runs these main. go files

play06:46

right this the same thing here with up

play06:48

with uh drop and all that stuff it it

play06:50

uses these these uh separate programs

play06:54

right very simple um you could use

play06:56

something like a CLI package like I said

play06:58

what's good what's bad it doesn't really

play06:59

matter this was just easy peasy without

play07:02

a lot of squeezy you know what I mean uh

play07:04

so that's that so the next step here uh

play07:07

like you let let me show up this make

play07:09

file right so I'm using a make file

play07:10

people say you should drop that in in

play07:12

favor for other

play07:14

stuff like I said man if make file works

play07:16

for me it works for me right maybe it

play07:18

doesn't work for you maybe you want to

play07:20

use something else that's perfectly fine

play07:22

right um it all depends what you want to

play07:25

use it doesn't really matter right uh

play07:27

it's

play07:28

fine all right because you have these

play07:30

goal tools I don't know go make or

play07:31

something you have these these cool

play07:33

stuff U where you can write goang things

play07:36

and but like I said a make file

play07:37

everybody knows it it's simple it's most

play07:39

of the time already installed on Linux

play07:42

things so it's fine right uh so the next

play07:44

step is a very important step is our DB

play07:46

I'm going to uh start with this DB

play07:48

because this is a little bit of

play07:50

controversial right so the DB package

play07:52

has just one file and what this does is

play07:54

basically creates

play07:57

um it it basically uh bootstraps or

play08:00

database right and as you can see we are

play08:05

using bun here but we and it's a global

play08:08

variable so there's a lot of things we

play08:09

need to discuss here right um so I

play08:11

started out we started out with using

play08:13

sqlc right sqlc is something that

play08:16

generates um goang codes and structures

play08:20

models based on U your schema your SQL

play08:23

schema uh and you can write your SQL

play08:26

queries and it basically generates code

play08:27

for that which is actually very very

play08:29

good right

play08:31

but need to drink some coffee for this

play08:33

one but the problem with sqlc is it's

play08:35

it's getting very tedious something we

play08:37

had a ton of queries already and I

play08:38

thought man this is just so nasty all

play08:40

these queries and then we have a schema

play08:42

for our migrations we have a schema for

play08:44

sqlc and you need to sync these things

play08:47

and then some people are working uh like

play08:49

me and Teddy we working on that it's a

play08:52

two people project right now and we are

play08:53

doing work for for 16 uh but the thing

play08:56

is that it's just it gives conflict it

play08:59

was was

play09:00

nasty for current operations I'll really

play09:02

like it but we need to have some

play09:06

more dynamically stuff going on some

play09:09

more genetic stuff and I used BN for a

play09:11

long time um in in other projects and I

play09:14

really like it right of course something

play09:16

that's the downside like I said for

play09:17

every positive thing also comes

play09:20

something that's some negative stuff and

play09:22

the cons for bun is that your queries

play09:24

are not going to be type safe right if

play09:27

you make a mistake

play09:29

that's bad for you nobody's going to

play09:31

it's going to it's going to give you an

play09:32

error or something or or user that not

play09:34

being found uh but hey it is what it is

play09:37

right like I said pros and cons what do

play09:40

you want it's it's a a weight scale that

play09:44

needs to be in Balan for you right not

play09:46

for somebody else on the internet it

play09:47

needs to be in balanced for you and for

play09:49

your team and is everybody thinks that

play09:51

the scale is in balanc and it's fine

play09:52

right everybody know the consequences

play09:54

here um but also everybody can use the

play09:58

positive side Ides on that right so

play10:00

that's what we do and it's a global

play10:02

variable why is it a global variable

play10:03

just for the ye of use and of course

play10:06

this is very this could be dangerous but

play10:08

like I said a global at the right time

play10:10

at the right place is is is okay it's

play10:13

it's it's no big of a deal because we

play10:16

are using this data

play10:17

folder and this data folder is most of

play10:20

the time is going to be used models for

play10:22

a lot of people but I think models is so

play10:24

weird because I think models they belong

play10:27

on the catwalk you know what I mean um

play10:29

it's I think everything that involves

play10:33

storing data retrieving data structures

play10:36

which is just

play10:38

data I think it it can be in a data

play10:41

folder it makes a lot of sense right so

play10:43

everything uh that's

play10:45

involving data

play10:48

structures queries for inserting or

play10:51

retrieving or updating whatever all

play10:53

database related logic is housing into

play10:56

this data folder right just like models

play10:58

most of the time

play11:00

and what this does is basically it uses

play11:03

it uses queries um it the only thing it

play11:06

does is basically interacting with your

play11:08

database right that's what it's doing

play11:10

you got have a query you're going to do

play11:11

some joints or some some separate

play11:13

queries you're going to aggregate that

play11:14

data and return it that's basically what

play11:17

this data folder is this data package is

play11:21

going to do right and nothing else and

play11:23

nothing nothing less and nothing

play11:25

more for tests it's very important

play11:28

because the global variables uh can be a

play11:31

problem in your tests but I don't like

play11:33

to test the data or your database into

play11:36

the unit form right I don't want to use

play11:38

unit tests for data I think interacting

play11:40

with your database should be on the

play11:42

integration Port again this is something

play11:44

that can be discussed it has its pros

play11:46

and it has its cons it really doesn't

play11:48

matter right um I think if you test your

play11:51

business logic based on on unit tests

play11:54

that's pretty good and if you use your

play11:57

data everything that needs to be

play11:59

interacting with your database if you do

play12:01

that on an integration

play12:03

level it doesn't really matter that your

play12:06

database is

play12:07

global the only thing you need to do is

play12:09

instantiate the correct database right

play12:12

if you have if you want to do some test

play12:13

you use a test database um and if you

play12:17

yeah whatever right and if you deploy

play12:19

the production you're basically going to

play12:20

init initialize your database with the

play12:23

production credentials right so that's

play12:25

the data thing right the next step we

play12:27

have is very simple is our handlers and

play12:28

our handlers are just plain functions

play12:30

right there are no uh you can see for

play12:32

example here uh some middleware where we

play12:35

validate gbt we have um some error stuff

play12:38

for centralized error

play12:40

handling some lock middleware it's very

play12:42

simple uses the S from gooling the new

play12:43

stuff pretty amazing let me show you

play12:46

something here can I show some something

play12:47

diff uh something interesting uh for

play12:50

example handle get User it's just very

play12:52

simple handle get user we always prefix

play12:54

this with handle and then we use get and

play12:57

that's not for example not for getting

play12:59

the user it's the get request right

play13:01

handle get user handle post user handle

play13:05

update user right um just a convenience

play13:08

method is that the way to go I have no

play13:10

clue it works for me

play13:14

uh you're you're like I said you're the

play13:16

ball pros of your painting you can do

play13:17

whatever you want right of course if you

play13:19

join a team um that already has these

play13:23

kind of things set out laid out yeah you

play13:26

need to follow them right but if you can

play13:28

choose from the start you can do

play13:29

whatever you want right as long as it

play13:31

makes sense for you um so what do we do

play13:34

with these hand handlers well uh like I

play13:36

said before we have the CMD API Maino

play13:38

file and then we have these very simple

play13:43

um uh yeah like like these these these

play13:45

route handlers right this these routing

play13:47

stuff so for example uh what we're going

play13:49

to do here because in leue we have the

play13:51

concept of sside accounts and buy side

play13:53

accounts because there's a double-sided

play13:55

marketplace where you're going to sell

play13:57

or you're going you're going going to

play13:59

auction your uh recurring Revenue in

play14:01

return for upfront cash from

play14:03

institutional investors right so we have

play14:05

sell site and buy side and of course the

play14:07

sell side they cannot they can only do

play14:10

specific certain actions and the same

play14:12

for the buy side so what we do here is

play14:14

we make this a group thingy which

play14:17

basically is most of the time in every

play14:18

single web framework you're going to

play14:20

have something like that where you're

play14:21

going to group your handlers with some

play14:24

um how do you call it with some

play14:26

middleware right and uh it basically

play14:28

some some authentication authorization

play14:30

middleware right he's going to see oh

play14:32

yeah this user is this a cide user yes

play14:35

then he can do these things if it's a

play14:37

buy side user then you cannot do these

play14:39

things right then uh you are basically

play14:41

not authorized to access these things

play14:44

right so that's what we do here handlers

play14:46

and then we're going to say handle

play14:47

cellsite demo metrics in this case we

play14:49

don't follow this stuff it's probably my

play14:51

bad handlers handle post funding request

play14:53

handlers handle get funding request you

play14:55

know what I mean very simple um no big

play14:58

of a deal here right so that's basically

play15:00

our handlers here then we have package

play15:03

um which is

play15:04

something where more of the business

play15:08

logic houses because most of the time

play15:11

you're going to have something like a

play15:12

transport right you're going to have

play15:13

your Json transport your Json HTTP

play15:15

Handler so what it's going to do is it's

play15:17

going to get some Json data it's going

play15:19

to uh Marshall that or decode that into

play15:23

a structure right and then you're going

play15:24

to have that structure and then you're

play15:26

going to decide do we need to do some

play15:28

business business logic onto that data

play15:31

or can we basically just use our data uh

play15:34

package and just store that user into a

play15:37

database right or store a funding

play15:39

request into a database some some simple

play15:41

crit doesn't really need to have some um

play15:44

business logic because it's very simple

play15:46

it's just receiving data decoding data

play15:49

validating data and storing data that

play15:52

doesn't actually is some kind of a

play15:53

business logic in my opinion but if

play15:55

there is some business Logic for example

play15:57

you need to fetch some transaction from

play15:58

the the bank you need to aggregate them

play16:00

do some calculations and all that stuff

play16:02

uh maybe some third party things are

play16:04

going on some third party API calls or

play16:07

need to be um executed then we put

play16:10

everything inside of a

play16:12

package folder here and in this case

play16:14

it's going to be salt and then client y

play16:16

yada y you can see the project is very

play16:18

very early in the stage we already have

play16:19

some project running but that's the next

play16:21

GS this is still in development right so

play16:23

that's going into package uh that's

play16:25

basically a goaling em to to put it in

play16:28

in package you could use it lip you can

play16:30

you can call it whatever you want but I

play16:31

think package is something that is very

play16:33

common inside of the goang community

play16:36

right then we have some types here uh

play16:38

and types is very important

play16:40

because you could put these types into

play16:42

Data but these types are basically

play16:45

shared you can use you can make you can

play16:47

you can call this common is is is I can

play16:51

I see that a lot of times in other

play16:53

projects in other repositories on getup

play16:55

people call it common people call it

play16:56

shared in this case just types because U

play17:00

the only thing we have is some kind of

play17:02

enums quote quote I need to be very

play17:04

careful for the YouTube police right

play17:06

because they are actually no enims but

play17:09

they act like enims right um constants I

play17:13

would say all the constants are here all

play17:14

the types are here that are shared

play17:17

between uh packages right that's in

play17:20

types um and you could basically split

play17:23

that out right you could make it a a

play17:25

file for each type but then you're going

play17:27

to have a file with three lines of

play17:28

sometimes that's who cares right you

play17:31

just dump everything into the types at

play17:33

go and if your types are getting too big

play17:36

then you can start splitting things out

play17:38

and group Things based on on domain or

play17:40

something right but that's for later on

play17:41

that's a problem we don't have yet right

play17:43

and then of course the UIL right util

play17:46

utils shared whatever you're going to

play17:47

call this is a very simple stuff where

play17:49

we going to have uh like nothing inside

play17:52

right is Pro app M and all that stuff

play17:54

some simple helper functions that are

play17:56

going to help you with uh simple simple

play17:59

things in your application right crypto

play18:01

is

play18:03

this not quite sure what this is

play18:05

probably T did some stuff right anyway I

play18:06

think it's for encrypting um some kind

play18:10

of API tokens we don't want to uh every

play18:13

API token from from a third party

play18:15

library for our user we don't want to

play18:16

expose that uh with plain text we want

play18:19

to basically encrypt that stuff into the

play18:20

database so if it's get hacked they are

play18:23

the hacker right not the client

play18:26

uh that's basically it of course get

play18:27

ignore go mod some make read me that's

play18:29

all that stuff that's basically it guys

play18:31

and with this project structure you can

play18:32

scale it as as far as you want right you

play18:35

because every data structure you're

play18:37

going to have or every data logic you're

play18:39

going to have is going to be in the data

play18:41

every new Handler is going to be in the

play18:42

handlers every new business logic you

play18:44

can put that into package and every new

play18:47

type you put it into type and you can

play18:48

scale it as big as you want is this

play18:51

going to change over time most likely it

play18:54

will right it's like I said it's

play18:55

something that works for me for a very

play18:58

long time this this structure it's very

play19:00

simple um don't make it too complex with

play19:02

all that clean architecture and

play19:04

hexagonal architecture and they will all

play19:06

have his benefits don't get me wrong

play19:08

like these are basically invented by

play19:09

very smart people but I always say start

play19:13

very simple right start simple make some

play19:17

uh diesel driven stuff and I'm going to

play19:19

show you how it looks right so you can

play19:21

see this is basically the sells side

play19:22

dashboard right um which again another

play19:26

question is like people say how do you

play19:27

make this beautiful wise well guys it's

play19:29

very simple uh don't be a single-sided

play19:31

developer very important people want to

play19:33

be a backend developer people want to be

play19:35

a front-end developer I don't think

play19:36

there is something such as a backend and

play19:38

a front end developer in my opinion you

play19:40

are a programmer or you're not you are

play19:42

an engineer or you're not you can solve

play19:45

problems or you're not because by the

play19:47

end of the day the only thing you do is

play19:49

write code right you're pressing buttons

play19:52

If it's JavaScript typescript goang

play19:55

python rust it doesn't really matter you

play19:57

can write it in every every single

play19:58

language there are some benefits and

play20:01

there are some cons there are some pros

play20:02

there are some Cons with everything in

play20:04

life and the only thing that matters is

play20:07

if your weight scale of pros and cons is

play20:10

inbalance or may basically if your Pros

play20:12

are a little bit

play20:15

um uh if if your Pros weigh a little bit

play20:17

more actually weit a little bit less

play20:19

right if the balance is a little bit

play20:20

more in the favor of the pros instead of

play20:22

the Conant it's a win for you right but

play20:24

that does not mean that my balance is

play20:26

the same my weight balance is going to

play20:28

be balanced the same as yours or my

play20:30

neighbors or whatever right or other

play20:31

produ um engineering teams it's all

play20:34

subject to the people are using it right

play20:37

that's something you need to uh take in

play20:39

consideration um that's basically the

play20:41

thing of course we are we are doing some

play20:43

stuff it's it's it's still in progress

play20:45

here we we we have some look at this

play20:47

it's it's we have some stuff but we're

play20:48

still uh working on that right that's

play20:51

basically it and it's calling basically

play20:53

spell kit in the back end and all that

play20:54

stuff maybe I'm going to make it another

play20:55

video because we're already 20 minutes

play20:57

in and I'm not even done it's crazy guys

play20:59

I really want to provide 10minute videos

play21:01

but I can because the things I need to

play21:02

say uh take some time right you know

play21:04

what I mean it takes some time so that's

play21:06

basically on B it if you have more

play21:07

questions feel free to dump it in the

play21:09

comments like I said uh is not for

play21:11

everyone right people going to going to

play21:13

dislike it people going to like it it is

play21:14

what it is it's the balance again right

play21:16

it's again the weight balance as long as

play21:18

the people like it or in favor of the

play21:20

people that dislike it it's all good for

play21:22

me Isn't it so thank everyone for

play21:24

watching this video and I'm looking

play21:25

forward to see you in the next video or

play21:27

live stream peace stay safe and have fun