{"id":1280,"date":"2021-01-27T17:06:11","date_gmt":"2021-01-27T17:06:11","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1280"},"modified":"2021-01-27T17:06:13","modified_gmt":"2021-01-27T17:06:13","slug":"golang-command-line-arguments","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2021\/01\/27\/golang-command-line-arguments\/","title":{"rendered":"GoLang: Command line arguments"},"content":{"rendered":"\n<p>Reading the golang official documentation is fun, today I saw the <code><a href=\"https:\/\/golang.org\/pkg\/os\/#pkg-variables\">Variables<\/a> <\/code>in package <code>os<\/code><\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-solid-color\"><blockquote><p>var Args []<a href=\"https:\/\/golang.org\/pkg\/builtin\/#string\">string<\/a><\/p><\/blockquote><\/figure>\n\n\n\n<p>It allows you to hold command line arguments and a simple main program that can help you validate this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\tif len(os.Args) > 0 {\n\t\tfmt.Println(\" More than one argument found: \" + fmt.Sprintf(\"%s\", os.Args&#91;1:]))\n\t} else {\n\t\tfmt.Println(\" No arguments passed \")\n\t}\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">go run main 1 2 3 4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>More than one argument found: &#91;1 2 3 4]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Why I used <code>os.Args[1:]<\/code><\/h3>\n\n\n\n<p>The argument <code>0<\/code> is the location of the exe itself in my case<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/var\/folders\/ry\/xrnmhhjx5_sdyq4mv8dk54s00000gn\/T\/go-build749979406\/b001\/exe\/main<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Reading the golang official documentation is fun, today I saw the Variables in package os var Args []string It allows you to hold command line arguments and a simple main program that can help you validate this. go run main 1 2 3 4 Why I used os.Args[1:] The argument 0 is the location of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1282,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[137,34],"tags":[149,23],"class_list":["post-1280","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-golang","category-technical","tag-commandline","tag-golang","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1280"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1280\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1282"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}