In this post, I want to write about a miracle in the software development world.
Imagine you can create your database entities with some clicks; you have many types of fields that are built in that software.
For a programmer who codes in pure PHP or python with a front-end framework, it takes more than 1 month to create a blog and shop website, but you can have all of that in one or two days with Frappe; Wow 🙂 What amazing!
go get {package path}
#### eg.
go get gorm.io/gorm
Display Current GOPATH
go env GOPATH
install new go package
go install test-app
Update package
go get -u test-app
List Packages Alongside Dependencies
go list
go list ./...
Display Version Information
go version
Maintain Module Dependencies
The go mod tidy command allows us to add missing dependencies or delete unused modules. This go command helps in maintaining module dependencies and keep your applications as lean as possible. Simply run the following simple command to do this.
Make sure to run this from your project’s root directory. You can check the go.mod file to see which dependencies were added or deleted. The -v flag, if used, causes tidy to display which modules were removed to the standard error.
go mod tidy [-v]
Verify Module Dependencies
go mod verify
Display Why Packages/Modules are Needed
You can see why certain modules or packages are required in your application. This is useful if you are working with someone else’s code or are trying to figure out what certain things do in a specific project. The “why” command of the mod tool allows us to do this
The first one is the general syntax, and the second one is an example. It prints out why the language and encoding packages are required in your application.
go mod why [-m] [-vendor] packages...
go mod why golang.org/x/text/language golang.org/x/text/encoding
when you want to run or build a go file it needs to be the main package (I’ll write more about packages in go later).
let’s div into example code
package main
import "fmt"
func main(){
for i := 0 ; i <= 500 ; i++{
s := ""
if i % 7 == 0{
s = "Haftaeiash"
}
if i % 3 == 0{
s = "Setayi"
}
if s != "" {
fmt.Println(s)
}else{
fmt.Println(i)
}
}
}
By default it prints the list as a shell script; however, if one or more variable names are given as arguments, it prints the value of each named variable.
Most web applications are implemented based on Rest Full APIs and as I researched huge part of them are not implemented based on best practices and clean code principles, so I decided to collect some points in a couple of posts to help make them more efficient APIs and Applications.
Let’s Look at other kinds of APIs
you can easily research and find out more about all of these kine of API design methodologies but here I’m going to just collect best part of them to create a document to implement Rest API in best practice.
Graphql
the best part of graphql is that you can design your API for the front end to just get whatever need, not more.
it can bring us better speed because less amount of packets is transferring over the network.
In this series article, I want to note some tips during watching Golang courses that are important for me.
Overall points :
golang is a compiled programming language
like as c and c++ it needs a main function
all built in functions are not available like as php and you need to import situble library
you cant define unused variable , function or even import unused library.
to print we need to import “fmt” library
it needs to specify variable type on definitions
some usefull commands:
go mod init mymodule
go run main.go
Golang Data types list
Masoud Hosseini | golang data types
Array and slice in golang
#array :
var booking [50]string
or
var booking = [50]string{"masoud"}
#slice
var booking []string
or istead of "var" we can use ":="
booking :=[]string
add an index to a slice
append(booking, firstName + "- "+ lastName)
loop in Golang
we have just “for” loop in golang
to ignore a variable you dont want to use you can use “unser line” => “_”
so with Go you need to make unused variables explicit
for example :
firstNames := []string{}
for _, bookingItem := range booking {
var names = strings.Fields(bookingItem)
firstNames = append(firstNames, names[0])
}
Using Types in PHP is one of the least used features, but very powerful features available in PHP. This is a feature that can save you and other developers a whole lot of stress (if you work with a team).
Of course, you can write function descriptions, but it becomes quite a daunting task to write function descriptions for all your functions and variables in a large project.
When someone else wants to use your function or even you want to use it after a couple of weeks later, it needs to check the function’s body to recognize which types you should pass to the function while using, if you don’t specify arguments types.
Ex:
function getItem(array $item) {
return allItems()[$item[0]];
}
This will make sure that whatever is passed in here is the type needed. You can read more from www.php.net