{"id":1714,"date":"2017-09-18T12:53:00","date_gmt":"2017-09-18T10:53:00","guid":{"rendered":"https:\/\/blog.alwaysdata.com\/?p=1714"},"modified":"2020-04-17T15:18:22","modified_gmt":"2020-04-17T13:18:22","slug":"heberger-une-application-go-avec-alwaysdata","status":"publish","type":"post","link":"https:\/\/blog.alwaysdata.com\/fr\/2017\/09\/18\/heberger-une-application-go-avec-alwaysdata\/","title":{"rendered":"H\u00e9berger une application Go avec alwaysdata"},"content":{"rendered":"<p>Le langage pr\u00e9sent\u00e9 cette semaine dans notre s\u00e9rie d\u00e9couverte est <a href=\"https:\/\/golang.org\">Go<\/a>. Ce langage, cr\u00e9\u00e9 en 2007, a&nbsp;une particularit\u00e9 importante par rapport \u00e0&nbsp;tous les autres d\u00e9j\u00e0 \u00e9voqu\u00e9s et support\u00e9s par alwaysdata (<a href=\"http:\/\/php.net\/\">PHP<\/a>, <a href=\"https:\/\/www.python.org\/\">Python<\/a>, <a href=\"https:\/\/www.ruby-lang.org\">Ruby<\/a>, <a href=\"https:\/\/nodejs.org\/\">Node.js<\/a> et <a href=\"https:\/\/www.lua.org\">Lua<\/a>)\u2026<\/p>\n<h3>Un langage compil\u00e9<\/h3>\n<p>Go est un langage compil\u00e9, qui ne n\u00e9cessite donc pas d\u2019interpr\u00e9teur pour faire tourner les programmes. Ce qui a&nbsp;une cons\u00e9quence majeure&nbsp;: Go n\u2019a m\u00eame pas besoin d\u2019\u00eatre install\u00e9 chez alwaysdata pour \u00eatre utilis\u00e9. La version 1.7 est toutefois disponible sur nos serveurs pour vous permettre de compiler vos programmes en SSH, mais vous pouvez tout aussi bien compiler vos programmes ailleurs\u200a\u2014\u200asur votre propre ordinateur, par exemple.<\/p>\n<h3>Exemple&nbsp;: d\u00e9ployer une application Macaron<\/h3>\n<p>Il existe naturellement de nombreux frameworks web pour Go&nbsp;; comme nous sommes gourmands (et fran\u00e7ais), nous allons utiliser le framework <a href=\"https:\/\/go-macaron.com\">Macaron<\/a> dans l\u2019exemple suivant.<\/p>\n<p>Pour illustrer le fait que le d\u00e9veloppement et la compilation peuvent \u00eatre faits localement, nous allons ex\u00e9cuter les commandes sur notre propre ordinateur\u200a\u2014\u200aici sous Linux, mais qui pourrait \u00eatre sous MacOS, Windows, ou tout autre environnement&nbsp;:<\/p>\n<ul>\n<li>t\u00e9l\u00e9chargeons Macaron&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \" title=\"Installer Macaron\">$&nbsp;go get gopkg.in\/macaron.v1<\/pre>\n<ul>\n<li>cr\u00e9ons le fichier de notre application, <em>hello.go<\/em>&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:go decode:true  \" title=\"hello.go\">package main\n\nimport (\n    \"os\"\n    \"strconv\"\n    \"gopkg.in\/macaron.v1\"\n)\n \nfunc main() { \n    m := macaron.Classic()    \n    m.Get(\"\/\", func() string {\n        return \"Hello world!\"\n    })  \n\n    host := os.Getenv(\"IP\")\n    port, _ := strconv.Atoi(os.Getenv(\"PORT\"))\n    m.Run(host, port)\n}\n<\/pre>\n<ul>\n<li>compilons le programme&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \" title=\"Compilation\">$ go build hello.go<\/pre>\n<ul>\n<li>nous avons d\u00e9sormais un fichier ex\u00e9cutable nomm\u00e9 <em>hello<\/em>. Nous allons l\u2019envoyer par <a href=\"https:\/\/en.wikipedia.org\/wiki\/Secure_copy\">SCP<\/a> \u00e0&nbsp;la racine de notre compte alwaysdata (nomm\u00e9 <em>superman<\/em> dans cet exemple)&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\" title=\"scp\">$ scp hello superman@ssh-superman.alwaysdata.net:~\/<\/pre>\n<ul>\n<li>derni\u00e8re \u00e9tape, cr\u00e9ons dans l\u2019administration alwaysdata un site de type&nbsp;<em>Programme utilisateur<\/em>, en indiquant&nbsp;:&nbsp;<ul>\n<li>commande&nbsp;: <i>~\/hello<\/i><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>C\u2019est tout&nbsp;: notre programme Go d\u00e9marrera automatiquement en allant \u00e0&nbsp;l\u2019adresse indiqu\u00e9e&nbsp;!<\/p>\n<p>Prochain langage \u00e0&nbsp;d\u00e9couvrir sur notre blog&nbsp;: <a href=\"https:\/\/elixir-lang.org\/\">Elixir<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Le langage pr\u00e9sent\u00e9 cette semaine dans notre s\u00e9rie d\u00e9couverte est Go. Ce langage, cr\u00e9\u00e9 en 2007, a&nbsp;une particularit\u00e9 importante par rapport \u00e0&nbsp;tous les autres d\u00e9j\u00e0 \u2026 <a class=\"read-more\" href=\"https:\/\/blog.alwaysdata.com\/fr\/2017\/09\/18\/heberger-une-application-go-avec-alwaysdata\/\">Keep reading<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"wp_typography_post_enhancements_disabled":false,"footnotes":""},"categories":[230],"tags":[175,142],"class_list":["post-1714","post","type-post","status-publish","format-standard","hentry","category-uncategorized-fr","tag-golang-fr","tag-langages-fr"],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts\/1714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/comments?post=1714"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts\/1714\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/media?parent=1714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/categories?post=1714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/tags?post=1714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}