Golang Web Application Project Structure - Golang Web Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay guys welcome back to the channel this is tutorial series number seven here in harlequin's code right now we have some real development web development here in martin's code we are about to start the basic structure first guys for our web application this is what we call this golang web application project structure so what we what is the ideal structure for our web application and then uh based on our local development pc here normally we will work on local development pc here and then we will after we finish everything and then or or in the other way that we can along the way we will test the application to our web development there in uh in uh in the cloud server in our uh linux cloud uh uh solutions there so uh we will be uploading these files so we there also must have some quite uh different uh structure so i will show you guys also as uh regarding this uh both the local development and then the and then our uh production web servers there so uh let's uh dive into this tutorial guys guys welcome back to the channel okay uh we will start this uh web development project structure first guys and then we can go along with another few videos prior to our regarding this uh web development web development here in golang so right now i prepare bit uh for this tutorial guys so right now for example this is our folder so this is our web project i call this as a go web app for example this is your project name go web app okay this is a bare plain simple structure here on it just a main folder and then there is a main.go in the web development here in golang always there is always of course there is always a main.go guy so for those who do not know yet okay so uh we will create few folders here and then where where is our html files to be stored all our static css javascripts all our bootstraps or whatsoever whatever you are using the css we will place here guys so inside this application okay so but uh when we launch to uh production server which is our ubuntu linux there's a quite a bit um different difference only for the static folder okay later i will uh show you uh on on this and we will walk through guys okay uh the first thing we will do is the main.go the main that go as always that this is our main portal it's like our it's like our main door for our house okay uh right now we can in a web development there is always this configuration um then the html and then all these uh javascript css all these things that you are that you are using guys for uh for any uh front and so right now we can also create our uh design is just a plain simple structure guys uh but this is the ideal uh structure for our web development in here in golang for first of all we need to have our config again and these are all packages guys so internal packages that we are we are using yet we don't we never use um any other external package yet so for example this is our config here and uh by the way we will do do some go mode here we need to initialize our project guys go mode init okay then the name is a go web this is your project name go web app for example and then the go dot mode has been created so there is a file here okay the current version of our goal is 1.15 as of this recording so these are all the things guys okay uh and then after this we will do uh this config for example our config here normally it will contain um all our configurations files guys like our constants all these things so we will deal with this we will create some functions here like this is our settings uh that go for example guys this is your settings that go where you can create this package called the config okay and then you have some constants these are all your constants to be here guys so like for example the site uh site for example short name as a string so you need to define clearly here and this one is a string for example this is your application name or a site name like a go for example go web go web app this is your uh for example guys this is one of your uh constant variables here normally we will have all this kind of thing guys okay like later we will just this is your you can put all the description here guys uh for example another one is the site um like for example site full name like all these things guys so go golang web application structure you know why we have these guys later we will uh use this for our web pages to be these are all the constant variables that um we don't want to store or it's up to you or if you want to store this in the database or in the table the mysql or something but it's not ideal guys these are all a fixed one unless you're creating a dynamic so all your static fix variables is ideally you can place here under the config internal package here which is the settings so it's up to you well whatever your name you can add multiple files here later we will add multiple files so these are all the site full name like um again you need to put something here guys so later we will just explain you can fill in all the information for example these are all your ideal things here your site domain name or address or whatsoever you want to be fixed here most especially also these are all our uh another one is uh what do you call this um site your layout guys i mean your um we have this uh header dot html and the footer for our web so normally we will have this kind of uh um structure guys so we don't want to be in like we don't want to keep repeating our headers like those are header.html so we will split all those information guys and then the footer but the the html body will be a different one so for example our site our html here guys so site header like for example uh template this is all these are all your templates here like what you call like your layout or something or this is our thing press hold on okay guys so uh to capture our time i fill up all this information and these are all the decent information already guys that we can properly uh like we have some real kind of a structure here guys so basically these are all the settings that go every time you put every all the constant variables here guys like all this uh site here your site full name the excite slogan all these things guys short name um this later on we will be using this uh because uh in our web pages we will put all this information like all this uh slogan and like in your home page or in your footer section like your site here that when your project or site normally we will have this kind of a year started and then all these slogan guys now the most important part here in this settings that go we will have this uh site root html these are all these things later we will create this okay so all our templates will be placed under this uh we will create this folder now uh html under this uh another internal uh folders here that we are about to populate later on and these are all our html guys so remember that all the configs all the servers clip as well here all your uh um what do you call like um like a db connection here uh we will create like a db.go like for example you have this um package config like your mysql later we will populate here all your connections all the uh necessary uh password or username or whatsoever the connection strings here guys so you also have here in this uh under this config but the same package name called this config and then these are all the site settings or all these things guys so you can have all these a constant here this one is uh all the project layouts for example this one guys um what do you call this site header uh this is the most important part here the site root html so we will map through this html later we will map this is what i'm talking guys and this is the site header template uh normally i will do this kind of thing i will this uh this is our bare html so it will just concatenate at the bottom here uh this part the site header and template the site header account template the dashboard if you after the user login of course we have our dashboard there um okay that one is a different layout there probably and 99 is different okay so in front of our html is all the publicly accessible pages without this authentication without the user login like your about page your contact page or whatever your home page whatever it is a publicly accessible page guys that don't have the users authentication process then we will do here all these uh what they call these site header these are all the layout here these are all our common layout for in front but you can rename this guys if you want but for you uh for me i prefer this kind of a layout okay so you have this uh another this from this html we have another folder called layout something as you can see there is a layout here and then you can populate this new file here like what they call this header header.html we also have this kind of footer that html so we have this uh kind of a layout uh you can also have you can also sub layout here something like a front layout or or by meaning like we can rename this as a um like a front okay then the header here is like a front also okay then you can also have like uh another for the dashboard um dashboard um this one is like a like a footer dashboard um something like that i guess uh this one is like a uh i layout for you in the guys so uh header dot i know sorry uh dash dot html so all these things are all the basic layouts here guys um later part we will populate this know what is uh this one we will call the header and the footer normally we have these kind of things in our layout of our html it's like a chunk base that we need to pre-populate and then in our html body there the contents probably most probably is like a dynamic page or dynamic data and will be loaded automatically all these things guys so these are all our layouts here we will leave blank for a while later we will populate again so these are all your html so probably you have your html your config and like your db connection here and then the settings and then there is an html folder uh here no need to declare the package guys like this type only you can declare as all the go scripting here so all the go scripting site will be placed here for all the common settings i repeat again guys for all the common settings your secret constants or whatsoever that you are placing here all your go or script scripting gopro go files are here for you all your common constants or settings for your site or your project like this for example our settings that go under this package config so we declare all our site name here all these things guys so again you can add more information here guys uh later along with our web development we will still reuse this uh kind of go web app so probably we will populate this and then we will create the simple crud uh create all these things and the basic current operation for for example the mysql database when we when we go to the web i mean go with the mysql database already so we will still use this uh project so okay guys so so far we have this html and the config okay okay guys so i added one uh configuration here guys uh to capture our time again okay so uh for example this is our common very common application i mean that all those uh [Music] what they call this all those constant variables guys like those top logo and then the domain name short name all these basic information from our for our site we already loaded here from these global variables here global underscore variables that go still under this package config we can reuse this later on we will embed this upon each request this is a very common that you want to load to your web page as well guys so we don't want to consume uh anything from our mysql that we need to for example like somebody as well or any of any of our databases that this kind of information is actually we can use constant variables and then this one will be very uh fast and let's consume memory for our uh database there so we don't want to stress too much our database because this one is a very common information that every pages of our site will be needing this needing this kind of information so actually we can use this to embed directly to our each of the pages there later on as we go deeper with our web development series here guys so later we will have some actual web pages that you can that you will be seen and then we can test along the way guys so these are all just a project structure first so basically you have this config here global variables settings so all these settings this one actually is from the con uh from the what they call these uh settings here guys so you can just create a small struct here to contain all these to collect all these information guys to our common structs here you can add multiple whatever you want that is uh very necessary for your site to launch or any pages there that need this kind of information then we can you can always uh modify these settings struct that we are we're adding here so we can add multiple and then you add here again guys from this variable site settings later we will embed this to each of the pages that written that some some user request okay so we will go again so right now we have the config the html or your html here you can create another folder for example your home page something like this guys so make it simpler guys and don't go much deeper to like any multiple sub and sub folders there because uh but it's up to you but it's hard to trace uh when you have this kind of a layout here okay so at least one level a second level or that one is is good enough guys so for example this is your html and that is that you have a folder like called all this layout and then if you have another folder here called like um what you call this front uh pages then you can have that as you wish then you can also have this uh like dashboard uh dashboard all these things guys so you can split all those html so that you it will not be disorganized guys so from we need to organize all those uh html files here like a front all these uh all this in the public html html that doesn't necessarily require and require an authentication something for the user so hold the dashboard to after the user login to your system or your online system or your kind of your site so we have this uh we can have this separate uh dashboard here and then you can have another folder if you want like like a per transaction here or something like that you can organize at least one or two folders is good enough guys don't go much deeper because um it might get irritate something just kidding okay so it just just up to two levels is good enough okay so like you have the accounts here like for example guys then you can have like any transactions like uh sales invoice you can uh you can make underscore here i guess this one is just a folder here in voice or something like that guys then in front here in front is um you can also organize but uh basically the in front section is uh much lesser um okay much lesser but but it's up to you with your own organization or your project requirements but basically you can create another folder as well same thing with the dashboard here like basic here like your home but not necessarily guys because unless you have a very big project then you can split here at the moment we don't want yet like for example in the front here like you have your index.html for example guys this is your homepage and then you can create another one like your about that html right about nothing so i guess just carry over and then you have these uh contact us that html all this kind of information guys these are all publicly accessible pages so like a policy or something or you have a dynamic pages also here uh it's up to you guys that you can structure like this like dashboard front layout here the layout is all your common um header and footer guys so you we can always split this information uh okay so we don't want to repeat your code like you paste again for the full time this kind of thing is sometimes uh you know just kidding okay guys so we don't want to repeat ourselves okay like this so all these things are layout for you already guys okay so these are all the public pages um i just leave blank first okay we have this front layout dashboard all these things okay so uh again we need to create another folder called for example our models not the model that you're thinking guys okay okay these are all the models here this one is for mainly for our database guys for our table definitions uh all our structs are there for example like because you have this here in the config so okay guys i i pre-populate for you uh for example these are all our models guys uh this is what i'm talking about for example you have a customer schema here all your tables or something like that gets all the definition of your database okay for the certain like like all these customer uh information like this is your main database you want to split but this one under the models here so you can have all your schema or all your uh fields or all your structs all your table definition fields and all these things okay so this one you can define under these models okay models means these are all your schema or you can rename like that guys so okay you can have multiple structs here all the customer related but still under these package models you can add another one like for example like your user user.go you can define here to organize everything guys because we don't want to plug too much of a rows here for like if you have a very huge database then it's very hard for you to organize guys because you need to split all this information but anyway these were all hosted in the same models like this package called the models and then you can split with all the customer related uh struct definition here you can always have that and then you have another user here or your any kind of a transaction like invoice.go for example invoices or invoice that go all these things yeah you can set up and define under these models here so we will organize uh easy for us to understand uh easy for us to maintain all these things guys so under all the same package code models okay so let's move on again from the config package i added this uh some example data here guys i got your database name is here your definition here and then your mysql database for example all the connection here this these are all my local development database here so later we will create a table there for you for our example in the future videos guys so i lay out for you all these html our web projects structure here first okay so we have our models we have our html we have our config so okay and then the main.go is always at the root of our project okay so again there is another thing that we need to tackle okay guys so another way is uh another thing we need to add most likely is for this structure here we need the static folder here guys the keyword is the static here all your assets images css javascript will be stored here and then this one we can organize as well like you have your assets here assets folder where you can store all your um another subfolder for these assets like your images and then like your gs all your css something like that guys okay so these are all used um these are all the structures here guys for example you can add anything you want here all your assets will be here as well okay and then um uh if you using a bootstrap guys i have here the bootstrap here guys um for example we are using this css the popular one which is the bootstrap 4. as a the moment there is a bootstrap 5 but still under the what they call this um still not yet maybe not yet stable guys so we will just use this um 4.5 which is us of this recording we use this bootstrap so i already downloaded this if you don't know yet now you can go and search for this uh getbootstrap.com or you can just straight away search in the google then like a bootstrap for then it will lead you to this uh application and then i've downloaded this then later part we will use this sample template here for our later on for our like we will create our simple or decent enough what we call this user's login system guys like for example you have this uh login here create a user send an automatic email to for email confirmation to activate the account and then password reset and then change password all these all these information for users system guys then we will uh we will be having this in harlequin's code so stay tuned for that guys okay so i already downloaded this to my local pc here so i am copying this uh by the way i i download these guys from this part which is this uh did the first uh option here you can have many options here but these are all the cdn if you prefer prefer the cdn but normally i don't use this um all this cdn part because we don't no need for us to worry because i remember that we have the cloud flare we already set up our cloud player that which is a very good caching also guys so we don't worry about all this cdn kind of thing but if you don't use the cloud flare then maybe probably you can use heavily on this kind of cdn i i recommend for you to download the source code here because anything happened for those uh those uh sources here but i i don't i don't think so anyone if something happened to the the server there then your uh pro might probably your application will be affected as well so if this one suddenly happen this one shut down or they close down all these things and then delete the file then it might have some interruption for your site but you can quickly replace it with the new one but it might have some bad user experience guys so i always download the source okay so that we have our own copy of this uh javascript css that we need from our site okay guys so i have i have these files ready here the css all the css here and then the gs all this information only guys i already extracted so we can copy this entire thing okay then i will paste to my local static here this is our project guys so i said we don't put under the assets guys we will do separate here this is what we call because these are all under the static so we will we will put this bootstrap for example or if you want to declare the bootstrap 4 it's up to you guys so we're just plain simple base here okay so now these are all our own assets here like these are all the css our own images logo or whatsoever the banner that we are using our own javascript we are using these are all our own assets you can have normally we will have multiples here outside of these assets we can we will have multiple like for example now we are adding this bootstrap guys uh then the bootstrap here all the bootstrap properties like if you are using another kind of [Music] javascript or something like other frameworks or like the drop down list you can you can create another folder here you can organize as well guys so you can organize all those those uh what they call those uh any kind of components that you're using uh as long that these are all publicly accessible guys what i mean is all those javascript css html that is publicly accessible without any authentication because normally we will later part we will upload this to our web server don't include any of the sensitive files under this static folder don't ever do that okay so here is the assets here all your public information okay so i hope you can capture guys all these things uh at the moment uh we will do this kind of a basic thing so uh okay this is what i'm talking about guys the static here early on i discussed this thickness when these are under the development here again this is stored locally on my pc here okay these are all our projects this is our project go web app then all these uh configurations here all these settings the start is here only guys uh if you're using uh some like some kind of a php or something guys um all your assets would be under these hd docks like you're using a samp x am am pp then you all your static images or must be placed with the under these hd docs but for golang web application we will use uh within our own project within our own uh we don't we are not bound to any other what they call these statics i mean all this uh framework like this samp for example we don't have a choice because they have a predefined structure structure for their folder okay so um we need to uh for golang project web application it it's really up to us guys so whatever right now i'm putting it to my uh the c drive all these americans gone so this is what i'm talking guys uh the samp here i also have the sam this this samp folder uh if you are a php developer and you know very well of this and then we all have these hd docs then you can place everything your thing here okay so these are all the quick one so all our static images html will be uh will be actually all here guys these are all a public one but later part in our web development all our as you can see our html also here these are all our html part here this one i'm talking about this one is all um external probably external sources so if you want to all your javascript are here guys so like images you cannot paste it here this one is this one under the layout it still remain under here because this one is no worries about here because uh you can also put this under this uh uh static but it's not ideal guys all these html should be bound here under our html folder okay so like dashboard here all these layouts but this one is most probably probably if you have so uh if you have a huge uh project uh web projects you can uh uh like most likely your external you can all use this uh kind of thing here like your images and logo your own css because all here will be rely on some css linking this one all your html this one is fine here inside our html folder anyway this one also will be loaded this one is just a structure only guys later it will be linked to um it will be linked to all these files here like the logo images uh kind of thing so um as you can see uh in our layout here uh one what i'm talking is like these guys for example um like your email logo or your site tab menu mino logo all these things as you can see it's already put under this static here static assets and then images like a harlequin snap logo for example so it will be and the images will be found here okay so these are all the the default constants that we are always uh use these files guys so uh always found in the static here okay okay guys so uh and then okay so these are all we have done this uh this part now in our this is our local development here uh later part we will uh uh in our next video we will have this uh what we call this we will about to start our web our golang web server here we will be using the gorilla mox and then the gorilla routers all these things guys so stay tuned for that in our next video okay so i will tackle okay guys so i also created this uh api guys so the last part is our api kind of thing uh you can name this uh like a controller or something guys but i prefer this folder or package called api these are all your routers here guys so this um this one i already pre configured for you guys so i already initialized this gorilla max here since this is our next step for our tutorial series here in americans code so i created all this api so these are all your home page like your any of your publicly accessible pages guys like um you can name this as like what they call this maharlikan's code like main routers or something like that guys so we can do this here this is what uh i'm talking about like the routers here this will be in our next video guys so no worries we'll explain further in our next video so this is our main routers here we can add multiples here at the same time like the as you can see that there is only a slash here so um this means that this is our homepage guys so this is our main functions here like uh this is actually calling the index.html so these are all the things guys that we are about to uh discuss in our next video so the last step would be from our project structure here is the api package here guys so we can add multiple uh files here as well like um like any of your um dashboard or something like that guys so uh any access any public accessible uh like if you are giving some urls or or publicly you have your some apis that you need to send to your customer or so your clients or to those users that need this uh need the data from your end so uh these are all the pre-configuration here guys so um later part in our next video we will discuss this so okay guys also our uh structure for our web development here in our in our uh web server guys uh there in the ubuntu there in the cloud these are all our produ uh what they call this um this is our project structure on the web i mean in our production site okay so under this var uh application okay actually we can hold on guys actually we can uh in we can upload this uh i think this one not yet i need to refresh let's rename the thing okay so this is our thing guys so this is remember this is this is our go web currently we just developed once we publish this to our site on the production there so that the everybody can access publicly now under this var and then this what you call and then www then html as you can see we have created this mahlikans.com this is our public structure guys this is our production structure early on i this one is our local development in our own pc here after we deploy we finish our project then we deploy to the uh our cloud server there then we will have all this kind of information also the structure guys as you can see this is a var ww this is for the ubuntu server guys okay so uh html marlacansko.com we also have this public html static this one we in our previous discussion for the nginx guys we already set this uh static folder here you can take a look on my previous discussion about these nginx and then we set up this mahallikans code okay so we will target this uh all the static uh what i mean this static here is a quite different from the production site okay this is the production site the static here is quite different path guys as you can see here okay but in our golang we don't touch any code there at the moment at the moment guys because this one is um this this settings is actually map we don't we don't want to change anything here as you can see the static here assets images uh is like a bare information guys as you can see but uh actually it's the same here guys um static public okay but it's automatically mapped for us by using the dagoria no worries it's too much of information to digest at the moment i know later in our next video for sure guys you will understand deeply uh right now is uh is uh the knowledge and the information is quite overwhelming okay so uh these assets here we will upload under this uh bar ww all these uh html marlicansco.com html then static okay so this is our settings here in the configuration i want to see in the assets here also css images all these then we can upload the bootstrap for also here or we can just rename also we will do the same okay so the bootstrap here will be uploaded also to the bootstrap here all your static so you just upload all the assets here bootstrap whatever you have here guys then you can upload here as well but again remember that the no sensitive information password anything don't include here guys but please okay then you can upload here all this uh go web like for example if i i can upload directly uh this go web here under this uh for example guys then i will just probably we can i can surface okay uh just leave it okay guys so we just want to clear out okay so i have here and then the static will be removed guys i just delete my i already uploaded i just delete this static it should not be here it should be in the public there okay so right now we have our config html all our internal html here okay guys this one uh don't confuse about this uh part guys because um these are all our the layouts here these are all the structure it structured html guys actually all the linking there all the sources are from the public html okay data should be here all the source files all the source gs javascript css images will be pointing here okay this html here is just a structure for us to lay out the basic html or our um like the holder like for example the table tdtr all these things guys okay the html body header title all these are locate uh it should be is here only but all the sources materials all these assets are found in the public accessible uh pages here these are all publicly accessible folders for your web server as you can see these are all the images of course you don't want to hide the image okay guys i hope it's clear right now i lay out for you all the structure from the development structure up to the production structure here okay whatever we do here in our local development we will publish here so that you guys you can play around when we have when we launch something for testing or web development for basic uh inputs like all those first name last name right someone gets a crud operations so we will be playing around you can also play around with your own pc there once we publicly publish whatever we have done here in our web development for golem so you can access accessible for our what they call these uh mahalikans maharlikanzcode.com this one guy so actually our infrastructure is already publicly accessible and right now it's just a plain hello marlikans so we can we we will add this uh later on that you have this kind of uh this kind of information here uh we will copy this uh from the get bootstrap example pages here then for us to play around and then we can have some login system there here in harlequins and then you can play around you can anything that we need to discuss or then register or something like that guys well we can play around for sure in the next video here so as we go deeper in mahalikans okay guys thank you so much guys for watching my video uh i hope i impart with you the knowledge and then the share with you with your my knowledge that i that i i have learned uh here in harlequin's code so okay guys okay guys that's all for today's discussion regarding this golang web project structures and then i lay out for you from the web development uh from from our development pc up to the production structure guys so i layout for you what is the complete overview of what you are going to do when you publish to the web development in our production site there and also our layout structure for our development pc so i hope you learned a lot here in my elegance code guys and if you never if you don't if you if you're not subscribed yet please consider subscribing guys so that you can have more videos like this and then you can have all this uh kind of information that i shared with you here in maharlikan's code thank you so much for watching may god bless us all thank you and bye bye [Music]
Info
Channel: Maharlikans Code
Views: 3,104
Rating: undefined out of 5
Keywords: Maharlikans, programming guides, step by step guides, go, golang web development series 7, golang tutorial, building scalable web apps in golang, golang good for web development, golang project structure best practices, golang project structure rest api, golang api project structure, golang web app structure, golang microservice project structure, golang web app folder structure, golang project structure 2020, golang example project
Id: AWf6BntPXtc
Channel Id: undefined
Length: 50min 18sec (3018 seconds)
Published: Fri Nov 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.