{"id":2252,"date":"2017-08-13T12:22:02","date_gmt":"2017-08-13T11:22:02","guid":{"rendered":"https:\/\/denbeke.be\/blog\/?p=2252"},"modified":"2019-05-18T21:51:58","modified_gmt":"2019-05-18T20:51:58","slug":"go-mobile-example-running-caddy-ios","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/","title":{"rendered":"Go mobile example: running Caddy on iOS"},"content":{"rendered":"<p>I while ago I did a small experiment to run <a href=\"https:\/\/caddyserver.com\" target=\"_blank\" rel=\"noopener\">Caddy<\/a> on my iPhone. I currently have no time to do something with it, and actually build a useful Caddy iOS app, but I wanted to do a quick writeup about how you can achieve this. So others can maybe do something with Caddy on iOS, because compiling a Go project for iOS is really easy!<\/p>\n<h3 id=\"installing-go-mobile\">Installing Go Mobile<\/h3>\n<p>You first need to install Xcode and the Xcode command line tools.<br \/>\nThen you can simply install Go Mobile with the following commands:<\/p>\n<pre><code>$ go get golang.org\/x\/mobile\/cmd\/gomobile\r\n$ gomobile init # it might take a few minutes<\/code><\/pre>\n<p>More information can be found in the <a href=\"https:\/\/github.com\/golang\/go\/wiki\/Mobile\" target=\"_blank\" rel=\"noopener\">official docs<\/a>.<\/p>\n<h3 id=\"building-an-ios-framework-bundle-from-caddy\">Building an iOS framework bundle from Caddy<\/h3>\n<p>Now you have to create a framework bundle of the Caddy project, which you can then use in your iOS application:<\/p>\n<pre><code>$ gomobile bind -target=ios github.com\/mholt\/caddy\/caddy\/caddymain<\/code><\/pre>\n<p>This will generate a framework called <code>Caddymain.framework<\/code>.<\/p>\n<h3 id=\"building-an-ios-app-with-the-framework\">Building an iOS app with the framework<\/h3>\n<p>Now you can just drag and drop the compiled framework bundle to the Xcode project of the iOS app.<br \/>\nCheck &#8220;Copy items if needed&#8221; if you want to include a copy of the framework bundle within the Xcode repo. Otherwise, modifying the Go package source code and rerunning <code>gomobile bind ...<\/code> will update the <code>Caddymain.framework<\/code> in the app.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-2253 size-large\" src=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project-1024x597.png\" alt=\"\" width=\"640\" height=\"373\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project-1024x597.png 1024w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project-300x175.png 300w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project-768x448.png 768w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project.png 1464w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>If everything went well, your Xcode project overview will look like this:<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-2254 size-medium\" src=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Caddymain-iOS-framework-bundle-in-Xcode-222x300.png\" alt=\"\" width=\"222\" height=\"300\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Caddymain-iOS-framework-bundle-in-Xcode-222x300.png 222w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Caddymain-iOS-framework-bundle-in-Xcode.png 518w\" sizes=\"(max-width: 222px) 100vw, 222px\" \/><\/p>\n<p>Once this is done, you can import the <code>Caddymain<\/code> framework in your Swift files and call the functions from the Caddy package and use them to start Caddy.<\/p>\n<p>I put everything in my <code>ViewController<\/code>:<\/p>\n<pre class=\"swift\"><code>import UIKit\r\nimport Caddymain\r\n\r\nclass ViewController: UIViewController {\r\n\r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \/\/ Do any additional setup after loading the view, typically from a nib.\r\n\r\n        \/\/ Don't forget to compile with ENABLE_BITCODE = 'No'\r\n        \/\/ Startup Caddy...\r\n        CaddymainRun()\r\n\r\n    }\r\n\r\n    override func didReceiveMemoryWarning() {\r\n        super.didReceiveMemoryWarning()\r\n        \/\/ Dispose of any resources that can be recreated.\r\n    }\r\n\r\n\r\n}<\/code><\/pre>\n<p>Now you can hit <code>run<\/code>, and you&#8217;ll be running Caddy on your iPhone!<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2255\" src=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Running-Caddy-on-iOS-with-Go-Mobile.png\" alt=\"\" width=\"2422\" height=\"1434\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Running-Caddy-on-iOS-with-Go-Mobile.png 2422w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Running-Caddy-on-iOS-with-Go-Mobile-300x178.png 300w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Running-Caddy-on-iOS-with-Go-Mobile-768x455.png 768w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Running-Caddy-on-iOS-with-Go-Mobile-1024x606.png 1024w\" sizes=\"(max-width: 2422px) 100vw, 2422px\" \/><\/p>\n<p>Note: since Go mobile doesn&#8217;t compile frameworks with bitcode enabled, you have to turn bitcode off in the project settings in Xcode: Go to the Build Settings tab. Type bitcode in the search field and change the <em>Enable Bitcode<\/em> setting to <em>No<\/em>.<\/p>\n<h3 id=\"conclusion\">Conclusion<\/h3>\n<p>Running Go code on an iOS device is easy!<br \/>\nSo don&#8217;t hesitate to do some useful stuff with it yourself!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I while ago I did a small experiment to run Caddy on my iPhone. I currently have no time to do something with it, and actually build a useful Caddy iOS app, but I wanted to do a quick writeup about how you can achieve this. So others can maybe do something with Caddy on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[235],"tags":[260,231,232,129,186,257,258],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Go mobile example: running Caddy on iOS &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go mobile example: running Caddy on iOS &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"I while ago I did a small experiment to run Caddy on my iPhone. I currently have no time to do something with it, and actually build a useful Caddy iOS app, but I wanted to do a quick writeup about how you can achieve this. So others can maybe do something with Caddy on [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-13T11:22:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-18T20:51:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project-1024x597.png\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2017\/08\/Import-Caddy-framework-bundle-in-Xcode-project.png\",\"width\":1464,\"height\":854},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/\",\"name\":\"Go mobile example: running Caddy on iOS &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/#primaryimage\"},\"datePublished\":\"2017-08-13T11:22:02+00:00\",\"dateModified\":\"2019-05-18T20:51:58+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/programming\/go-mobile-example-running-caddy-ios\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/2252"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=2252"}],"version-history":[{"count":1,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/2252\/revisions"}],"predecessor-version":[{"id":2256,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/2252\/revisions\/2256"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=2252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=2252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=2252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}