
The final part of a series of articles about my experience of switching from PHP to Go.
The first part ,
second ,
third ,
fourth .
4.5 years ago I had the imprudence to start writing my cryptocurrency in a completely inappropriate language for this business - in PHP. As a result, of course, I wrote (I am stubborn), but it turned out to be a crutch on a crutch and that it worked at all was just some kind of magic.
')
I just want to warn you, I’m a self-taught programmer and I write code, to say the least, imperfectly.
It all started with the fact that I broke up with a girl named Katya and on the same day (April 4, 2015) decided to study Go and rewrite my cryptocurrency. I can’t write about Katya not under the spoilers; Habr is still for IT-related articles, and not for love stories and harsh IT people who are interested in Go, can simply not pay attention to spoilers “about Katya” and “about Masha”.
A total of 8 months: the application runs on
Win, OSX, Linux, FreeBSD ,
Android ,
IOSGeneral code ~ 73k lines, code for different OS somewhere a few hundred lines.
40k - processing / generation of blocks / tr-s, 17.5k - controllers for the interface, 15.5k - templates.
PostgreSQL, SQLite, MySQL are supported.
Those who will test my creation, I warn you - there may be bugs, and if you have time, drop a line about them, please, at
darwin@dcoin.club or in a personal on Habré. Suggestions and advice are also welcome.
In the first four parts, I talked about how a web server works in dcoin, about
html / template , databases, smooth application termination, encryption and parsing of blocks, Android application.
In this part I will tell about compilation under IOS.
Start
The first difficulty was that I did not have a developer certificate. And without it, the application could not be compiled. I didn't have an iPhone either, as well as Mack. Day 3 was fiddling with installing osx on virualbox, in the end I could only install on vmware and establish a network with a virtualbox to work in the console.
I found out that in my luck, in xcode 7 there was an opportunity to compile applications with a free certificate that anyone can create. And the iPhone 4s was lent me very much in time. It was possible to plunge into the development.
About Katya(In previous parts):
I wrote to her at VK, said that she had forgotten the bodies at home, and now she was with a friend. I wrote that I would wait for her. Then he received "Do not call and do not write me more !!!!". He didn’t ask any questions, called the next apartment, asked me to send the flowers to Kate when she was home. I came home, a few hours later I decided to rewrite Dcoin to Go.
A couple of days later I wrote to her that I was leaving for several months with my head in my project and asked me not to bother me over nothing.
A week later, Kati came sms-ka hello. Well, how are you? ”. I did not answer. A week later, another "hello. how are you?". I did not answer again.
About a week later, she wrote that she urgently needed 7 tr. in debt, because she does not have enough to pay for the apartment. I answered "OK". The next day she came to my house.
I do not know what she had in her head, she probably thought that I would pester her. She was kind of weird all evening. I was cold and tried to avoid any contact with her. We ate, drank tea. Katya said she needed to go home. I called a taxi.
When accompanied her to the taxi asked:
- We are not together right? Those. I can do what I want?
She: - In the sense of "what I want"? No, we are together (moves up to me)
I: - Well, we didn’t have a first date, we have not started everything from the beginning.
She: - So it was just that.
I: - What a date this is, you just came for the money.
We were already at the door of the taxi, I got her down, paid the driver, she left.
In the morning the phone rang, it was Katya. I did not pick up the phone.
The next day, she sent a sms-ku "hello. I called yesterday, you did not pick up. " I did not respond.
A week later, she wrote that she received a ZP. and wants to throw money on my card. I did not answer anything. A few days later she wrote “hello. how are you?". I ignored again.
About a week later, I finally ran Dcoin on the nodes and saw how the generation of the blocks was going on and how they were flying between the nodes, filling the databases. It seemed to me that this can be considered the end of my temporary retreat and I wrote to Katya.
She responded very positively to the fact that I came in contact with her, agreed to meet. Then she said that everything was bad for her, the girlfriend with whom she rented the apartment moved out and that she was crying every day because of stress, she also decided to quit. I decided that when we met, I would suggest that she move to live with me and not bathe about anything.
It compiled and started everything without any special problems. Opened in the browser and ... nothing. But if you go through the network at
127.0.0.1 : 8089, it would give out a wallet. It became obvious that when you press the home button, the application goes into some kind of sleep mode.
By analogy with the android decided to make the service. But, it turns out services on ios are impossible. The maximum that can be done is to hang 600 seconds in the background. So it is, of course, logical - the struggle for the safety of the battery. In general, I had to learn how applications in ios generally work there.
About KatyaAs a result, Katya never arrived. Again there were some excuses. It ended with the fact that she sent me again. This time I did not think to leave immediately, because felt that she needed. But Katya too much wanted me to leave and I had to leave her alone. And promise never to call and write to her again.
I created a simple application in xcode, I threw it on the phone, it works. I began to dig up the file structure and at the same time look for something similar in gomobile, found
this file . I learned about NSLog, determined the place where he gives info
I remember my joy when I saw the lines in the log that my application displayed. It was cool, the connection is established, it will be easier further. For me, the ability to write and read logs is probably the most important thing when developing an application.
About MashaAgain began to look for a girl on dating sites and in VK. I forgot to mention that I keep myself in excellent physical. form, because at home there are a bunch of pancakes, 2 bars, dumbbell necks, a bench and a horizontal bar. And I look at 20 with something, although I am already over 30. I quickly found a girl who liked me and wanted to meet me.
Objectve-C, I did not know, and now I really do not know. But it was obvious that without understanding, at least, the syntax will not work. I read the lessons about Objectve-C a little, it became easier to understand the code.
Googled about the background mode, found out that it was necessary to add such code in didFinishLaunchingWithOptions
And add to info.plist
<key>UIBackgroundModes</key> <array> <string>fetch</string> </array>
Gomobile generates its info.plist. You can edit it
here .
About MashaOn the first date, I was 10 minutes late. When I saw Masha, I immediately thought “Wow, and I am lucky,” she was very much in my taste. We walked through the park, rode a boat, then I said that I needed to eat protein foods, otherwise the muscles would not grow and led me to our home. After eating chicken meat, let's go to the bedroom to watch a movie. But after 30 minutes, she said that she needed to go home, because she feels unwell because she is not yet completely cured of a cold. Called a taxi. Masha left.
webView
The fact that everything worked in the browser was of course cool, but this was enough for only 3 minutes, because when the browser opens, the application goes into the background mode and drops after 3 minutes. Without webView here in any way. For quite a long time I understood where and how to insert a webView so that it is displayed. There is no GUI, everything must be written in a text file, and considering that I was not familiar with the development under IOS at all, it was very hard for me
In the end, of course, everything turned out and turned out to be extremely simple.
About MashaThen during the week she said that she was working and had no time to meet, and we could only see each other on Sunday and not earlier than in 2 weeks. I said that I would just come to me after work, we live side by side, and I don’t like to see each other once a week. She replied that she would think.
A day later, she wrote that she was afraid to go to the unfamiliar guy for the night. I said that I thought she was missing at the ends and had almost begun to date other girls for the weekend. She got angry, swore.
The next day I sent jokes for the sake of sms-ku "All day on a date, I ride on a boat, in calluses of the hands and not only." She did not understand the joke, she became angry more than ever, she had to explain that they said it was a joke, I was at home all day, I wrote the code.
- (void)viewDidLoad { // 3 , - , . dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSThread sleepForTimeInterval:3.0f]; // dispatch_async(dispatch_get_main_queue(), ^{ // webView self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1:8089"]]; self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; self.webView.scrollView.bounces = NO; self.webView.scalesPageToFit = NO; self.view = self.webView; self.webView.delegate = self; [self.webView loadRequest:request]; }); }); [super viewDidLoad]; }
Our webView should be added to the ViewController interface.
@interface ViewController : UIViewController<UIWebViewDelegate,UIScrollViewDelegate,UITextFieldDelegate> { IBOutlet UIWebView *webView; ..... } @property(nonatomic,retain)UIWebView *webView;
About MashaA day later she said she was ready to come to me for the night. Apparently jealousy defeated fear. I, frankly, very surprised. Just in case, he said that I wouldn’t put a finger on her if she didn’t start the first one, just have dinner, chat and go to bed.
Notifications
“Since everything is so simple, then we need to make notifications,” I thought.
Objectiv-C code had to be implemented in Go
About MashaHe sent a taxi to her, met her, went up to me, had dinner, watched a movie. The time was already late, I had to go to bed. She said she would sleep on the guest couch, because with me in the same bed she is not ready yet. "Well, no, so no," she laid on the couch. After 5 minutes, she comes in and says that she has never had “this”, but she really wants it. For me, it was a pleasant surprise. In general, that night we did not sleep.
In Go code, use the following: sendnotif.SendMobileNotification (“Title”, “Notification Text”)
And in didFinishLaunchingWithOptions you need to add:
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
This is so that when the user starts, a message pops up asking for permission to use notifications.
About MashaOn the 4th date, I invited her to move in with me. Masha agreed. I drove to her in a hostel and moved things.
Conclusion
This concludes a series of articles about my experience of switching from PHP to Go. I hope my material was useful to someone. If you have questions about cross-platform development on Go, write in a personal, I will help.
About Masha and KatyaIt took about a couple of weeks. Late evening, lying with Masha on the bed, watching the Interns. Katya calls. Drunk He says that he asks forgiveness from all, and that she swallowed sleeping pills and will die in a few hours. I was confused, did not know what to say. I tried to find out where she was, to send the police and the doctors to her. Then I wrote to her best friend so that she would give her address and contact Katya urgently, for some reason she wanted to say the address. I called Katya and heard a drunken voice in the background. Everything became clear, this is a bluff, she is having fun with her girlfriend. The next day, I became convinced that everything was fine with Katya, since she was online.
Already the 6th month I live with Masha. Recently brought a cat.
PS
In Dcoin now you can get free coins (enough to pay for an Internet for several months).