Загрузка...

Golang Web Application Project Structure - Golang Web Development

In this Golang Web Development Series #7, we will learn how to structure Golang web application project from local development to production server with Ubuntu 20.04 LTS with step by step guide here in Golang's Web Development Series. Get Linode Account: https://www.linode.com/?r=6aae17162e9af054062c47ab53e14e517b380516 Maharlikans Code Github: https://github.com/maharlikanscode/golang-web-development-series #MaharlikansCode #GolangWebDevelopment7 #GolangWebAppProjectStructure #GolangTutorial #LearnGolangWebDevelopment #Golang #LifeAsSoftwareDeveloper #Maharlikans #FilipinoSoftwareDeveloper If you go with extra mile for buying me a cup of coffee, I appreciate it guys: https://ko-fi.com/maharlikanscode Source Codes: api/main_routers.go: package api import ( "gowebapp/config" "html/template" "net/http" "github.com/gorilla/csrf" "github.com/gorilla/mux" ) func MainRouters(r *mux.Router) { r.HandleFunc("/", Home).Methods("GET") } type contextData map[string]interface{} // Home function is to render the homepage page. func Home(w http.ResponseWriter, r *http.Request) { tmpl := template.Must(template.ParseFiles(config.SiteRootTemplate+"front/index.html", config.SiteHeaderTemplate, config.SiteFooterTemplate)) data := contextData{ "PageTitle": "Welcome to Maharlikans Code Tutorial Series", "PageMetaDesc": config.SiteSlogan, "CanonicalURL": r.RequestURI, "CsrfToken": csrf.Token(r), "Settings": config.SiteSettings, } tmpl.Execute(w, data) } config/db.go: package config // DBName is the MySQL Database name for the app "mkc" const DBName = "mkc" // DBConStr is the MySQL Database connection string const DBConStr = "root:@tcp(127.0.0.1:3306)/mkc?parseTime=true&charset=utf8mb4,utf8" config/global_settings.go: package config // Settings is where the common settings.go constant variables. type Settings struct { SiteFullName, SiteSlogan, SiteBaseURL, SiteTopMenuLogo, SiteProperDomainName, SiteShortName, SiteEmail, SitePhoneNumbers, SiteCompanyAddress string SiteYear int } // SiteSettings defines all constant variables from the settings.go var SiteSettings = Settings{ SiteFullName: SiteFullName, SiteSlogan: SiteSlogan, SiteBaseURL: SiteBaseURL, SiteTopMenuLogo: SiteTopMenuLogo, SiteProperDomainName: SiteProperDomainName, SiteShortName: SiteShortName, SiteEmail: SiteEmail, SitePhoneNumbers: SitePhoneNumbers, SiteCompanyAddress: SiteCompanyAddress, SiteYear: SiteYear, } config/settings.go: package config const SiteShortName string = "GoWebApp" const SiteFullName string = "Maharlikans Code" const SiteSlogan string = "Hello Maharlikans, Welcome to our Web Development Series" const SiteYear int = 2020 const SiteRootTemplate string = "html/" const SiteDomainName string = "maharlikanscode.com" const SiteProperDomainName string = "MaharlikansCode.com" const SiteHeaderTemplate = SiteRootTemplate + "layout/header_front.html" const SiteHeaderAccountTemplate = SiteRootTemplate + "layout/header_account.html" const SiteHeaderDashTemplate = SiteRootTemplate + "layout/header_dash.html" const SiteFooterTemplate = SiteRootTemplate + "layout/footer_front.html" const SiteFooterAccountTemplate = SiteRootTemplate + "layout/footer_account.html" const SiteFooterDashTemplate = SiteRootTemplate + "layout/footer_dash.html" const SiteBaseURL = "http://127.0.0.1:8081/" const SiteTopMenuLogo = "/static/assets/images/maharlikanscode_top_logo.png" const EmailLogo = SiteBaseURL + "static/assets/images/maharlikanscode_top_logo.png" const SiteEmail = "support@maharlikanscode.com" const SitePhoneNumbers = "" const SiteCompanyAddress = "Your company address here" const SiteTimeZone = "Asia/Manila" const SecretKeyCORS = "n&@ix77r#^&^cgeb13w@!+pht^6qu-=(" const MyEncryptDecryptSK = "mkc&1*~#^8^#s0^=)^^7%a12" models/customer.go: package models import "time" // Customer model is a master list for all your customers table type Customer struct { ID int64 `json:"id"` FirstName string `json:"first_name"` // required LastName string `json:"last_name"` // required CompanyAddress string `json:"company_address"` // required TelNo string `json:"tel_no"` // required FaxNo string `json:"fax_no"` // optional ContactPersonName string `json:"contact_person_name"` // optional ContactPersonNo string `json:"contact_person_no"` // optional CreatedBy int64 `json:"created_by"` CreatedDate time.Time `json:"created_date"` ModifiedBy int64 `json:"modified_by"` ModifiedDate time.Time `json:"modified_date"` DeletedBy int64 `json:"deleted_by"` DeletedDate time.Time `json:"deleted_date"` IsActive bool `json:"is_active"` } static/ - assets - js - css - images - bootstrap - js - css Your folders list must go on.

Видео Golang Web Application Project Structure - Golang Web Development автора Работа с графикой и изображениями
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки