Build a Microservice with Go and GoLand

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

People should stop calling a hello world CRUD app as a microservice.

Other than that pretty good.

πŸ‘οΈŽ︎ 35 πŸ‘€οΈŽ︎ u/kkweon πŸ“…οΈŽ︎ May 20 2020 πŸ—«︎ replies

I watched this when it was a live webinar. There were a few basic themes:

  • Tips and tricks for the Goland IDE
  • Writing a Go application
  • Using a library for web services
  • Using a library for database access.
  • Creating Docker build files
  • Publishing to Git

I found it to be far too information dense for a 90 minute presentation. Each of those themes could have been their own 15-20 minute presentation with a bit more detail, less rambling, and fewer tangents.

πŸ‘οΈŽ︎ 13 πŸ‘€οΈŽ︎ u/DaemonAegis πŸ“…οΈŽ︎ May 20 2020 πŸ—«︎ replies

Using HTTP as RPC? It is not the brightest idea ever. You better show an example of gRPC microservice as it is a default option for new projects.

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/ForkPosix2019 πŸ“…οΈŽ︎ May 20 2020 πŸ—«︎ replies

Would have liked to follow the tutorial, but unfortunately i donβ€˜t have a spare kubernetes cluster

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/nofoo πŸ“…οΈŽ︎ May 23 2020 πŸ—«︎ replies

cool stuff πŸ‘

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/martins_irbe πŸ“…οΈŽ︎ May 19 2020 πŸ—«︎ replies
Captions
today we want to have a look on how to build a go micro service using goal and to do that I created a project or a D which is a simple hello world using an HTTP handler but I'm obviously not going to go through all these steps to do it or you will be able to get the recording out at the end of this and go for the new code as well before we start let me make this idea a bit nicer for you all to see and convert it to my usual work environment using the Zen mode in case you wonder what setup I have I'm currently running on Windows I'm going to use the current abilities that are running on Windows and for the ID I'm using the latest version twenty nineteen twenty twenty point one point two with just a few plugins installed among which one that will be able to show you which actions I'm using when I'm pressing shortcuts called the presentation assistant and this one will show you shortcuts at the bottom of the screen shortcuts are available for Windows and Linux and for Mac OS ok so with all the setup out of the way let's see what we want to do today so today we want to take this service from a hello world or convert it to a service that talks to a database and in this case I'm going to use possibly a sequel and then I'm gonna use Jason to reply with something from that just from the Postgres database to our consumers finally we'll also run this into what could be a development environment or even staging or production using to burn eighties I created this project using our core modules support and you can do the same using the file new project or using the wizard at the beginning of the PI D launch you can select your modules and then you simply point it to the location if you don't have go already installed you can install it either from a local source or you can download it from the internet set some environment variables for the project means especially the go parks values for example and you don't need to worry about rendering mode as of go on 14 so all the setup steps are in place now let's let's switch to our project so when I switch to the Zen mode one thing that it hid from us it's the project tool window and in the project into a window if I bring it on the screen you can see that we have a few files that are created ahead of time I treated these mainly because it's boiler code and it's repeatable so once you will have these you will be able to replicate this in your setup as well keep in mind that everything that you find here it's still for a demonstration purpose and you shouldn't have to run it in production without checking with your company for security and so on we have a few files that are for example the database and web EML files and those are the abilities deployment files the docker file which also has a docker debug docker file debug which will assist us for docker and our go mod file let's start with deploying our database to kubernetes and see how that works and when once we did that we'll be able to switch back to go and actually do some coding one way to do this would be to go with the mouse and so on and another way would be to invoke the navigation bar and you can use the shortcut of course for it and then you can say oh I want to go to this navigation bar and say I want the database llamo file if we look at this ml file here we see that it has the regular content of what you'd expect for a torrent is deployment to be for database it's a stateful set it contains some config and it contains a service but there's no way visible to run this we can go to the plugins section in our settings or preferences and search in the marketplace for the turbinate is plug-in once we amenities plug-in and we install it we are then given the option to actually make the Yama file a bit more useful by having some assistance from the IDE what you've seen here is me installing a plug-in and not having to reload and this is available for some of the plugins already in the marketplace with others being converted you do require to have the latest twenty twenty point one release in order for this function to work okay moving on so now we see that we have some gutter icons and we may be familiar with these from our goal coding for example we can navigate around or we can even run the file so let's run the file in the dr context that I currently have configured this will bring up the services tool window this service tool window is the place where we can get information both about docker and about to burn eighties but unfortunately I don't want to have to share my screen between the editor and the service tool window so what we can do is come here to the option menu and select the View mode to be a window also you can do once we do that it's going to be basically a standalone window that we can switch between with using the window manager in our operating system and we can also navigate around the contents much better so for Communities roland offers you a overview of what your cluster contains and in this case you have workloads and in the workloads you can see the pods that are running deployment stateful sets and so on as well as their status and if they are ready or not you can see storage for example and see if there is any storage attached to your cluster you can see the configuration including all the namespaces that are available as well as some network information and for example what service is running so it looks like our deployment succeeded and everything is up and running our pod seems to run and everything should be fine we should be able to connect to the database so let's connect to the database how do we do that if we go to the services we will see that we are exposing the port 30,000 4 3 2 and this is just a random port I selected on during the deployment how do we connect to the database you'll say do I need a separate application or something like that and the answer is no goal and offers the functionality that you can find in data grip our database focused IDE and if you come to the side panel here on the right side which is the default place for it you'll be able to configure the database there's data sources properties and in this case I will make this a bit bigger and sorry for doing all this resizing you shouldn't need to do it but custom resolution for a webinar the important place in part is that we are running this database support for multiple database providers so for example we support Amazon redshift we support MongoDB we support Postgres equal or called my sequel sequel light and so on and what we are interested in right now is our post critical support what you've seen me doing is using the speed typing feature which allows you to quickly filter through lists so whenever you use the IDE and there's a list perhaps you can actually quickly type where you want to go and the ID will do the filtering and navigation for you so let's create this we have the Postgres login information prefilled we know that the parties will be different and we are going to use a username and password that we configured ahead of time I want to configure the database as well in this step and then I want to test the connection and as you can see we get a green indicator that everything looks ok what we can also do is beyond configuring options and other advanced settings we can also navigate to schemas and have a overview of all the schemas that are available for us and in this case we'll see that there's the default post Chris keema and there's the Golan schema which we created and in this we are interested only in the public part because we'll use that a lot for our application so let's configure to view only this leaving this other information out once we do this the ID will bring up the database console here and the editor for us to run queries and what you see here happening with the gofer progress bar is the ID indexing the database how does the index work for the database you may ask well for the databases we actually are able to infer the tables and for each table all the properties that they have four columns and so on and we can also for example look at sequences Golan as I said includes all the features that you find in data grid which means that you can also quickly have a look at the data editor so you can edit and view the information in the database that you have or you can use the source editor or you can use the other features that we have for navigation and so on to actually either edit the table or to make either an export or anything like that so you can right-click on on the for more information you can also modify the table in a visual manner and this will bring up a tool window that allows you to do that we are not going to do this anyway today because our table is already configured so let's go back to our project and bring back the navigation bar and say that we want to navigate from our database console to somewhere else you can see that you can actually do that right okay how do we bring back our files though well for our files we can invoke the navigate file and we can say show me the database yellow because this one contains one more useful information all the database that you'll see here is configured through this import script the import script that you find here in its sequel is actually part of our project if you had a look on the project overview and once we select that and invoke T go to file we can automatically go to that file now I'm not going to keep the database or definition there but just know that you can read this file and configure it however you want so that you can actually customize your microservice another useful option that we we have from data grip is the fact that you can use completion here for example to write your sequel statements all of these being done we can drop back to editing some code and let's go to our mango file so let's turn this into a service that connects to a database right we've seen the database up and running we've seen that we can connect to it safely let's make sure that we have something that puts to the database from the go side to do that I'm going to use the sequel X package and there's a function in it that I know it's called sequel X dot connect now the idea will tell me there's nothing that I can do here there's a red import here so the way I'm going to do this is going to expand the imports and then I'm gonna add automatically the sequel X package in the process I'm going to rely on Holland to complete the import package also because I know I'm going to connect to the possibility database I will all import the driver for Posterous and specifically in this case I'm going to use the leap PQ driver now both imports are written and you'll say wait a minute but you said you're completing and so on your land will also need to synchronize the project because right now if we are looking at our core modules file so if we go here and we haven't touched it so far this is going to show us an empty file right it's going to be the default in draw module file for a project there's nothing useful there so there's no way for goal end to actually know which dependencies our project relies on so let's use the synchronize dependencies of our project action and allow going to invoke the go tooling to download everything and you will find the commands that goal and execute if you expand the setup area here where it says go set up calls you will find this throughout running your application debugging it or fraud testing and you can see that we will set the door root to be going 14.2 in this case and go pass that's to go path I have and we run this command go exact not tidy to tidy up the packages and so on right so there is a typo that I have here and well there's only one way to really solve it because going can only do so much it's I'm gonna use the proper package name okay so moving on we have to provide a try for name in this case Posterous equal and we have to provide a data source but for the data source I haven't created it so let's created and what I'm going to do is I'm gonna use a life template which I defined in my previous projects and with this life template what I'm able to do is I'm able to expand this into a full-blown string because I can never really remember how the connection to the database should be done so I know that this information is correct I want to use this username and password but here I want to use a placeholder because this is going to be useful when we move towards abilities cluster where we don't necessarily hard-code the after our database and port looks ok the database name and so so I said I'm gonna move these to a data database cluster and I have a placeholder what that means is that I will probably have to get that information from somewhere and let's say we are going to take this from the environment and I'm going to use for that a DB house variable and I can either let go and import the OS package or I can do some piping or I can say yep and sorry for that and the will automatically import division so because I didn't have the correct name in the first place : can do it better for me and not worry about taste sensitivity of function names let's call this DB host now if this one is empty I do want I to have a fallback and I'll try to connect to the local host then host to become local host right and now the final step would be to go back to our data search here and say I want to print off this one way to do it would be to go in front of it and type and so on another way would be to have dot and then press control space twice not once as you see on the screen and start typing as printf which will automatically import the FNG package and select create function for us so now all I need to do is use the B host here and that's it okay so moving on another thing that I will do here is that I need to handle the database somehow so if we go at the end and say far we can actually get suggestions for how we should name this so let's name it DB and well it's an error value so let's name it error and if I have to try the if whole error and so on it's not gonna get us fast anywhere so I can use the if template here or I can use the earth but not new which I like more and then I'm gonna say log that fatal line and then error and I usually wrap this using the log package now Golan wasn't sure which load function I want to use because there are two of them and they have the signature that corresponds to my usage so it asked me do you want to import log one or you want to import the one from App Engine and I want to import the East End library one and in this case it knows even better than I do where the package and function name is okay so moving on to where my code is I also missed handling this one here so I can just say I want a variable here as well and I'm gonna name it error as well and the idea automatically added the correct sign for me so again not meal here and then have the other hand and that's it we handle errors cool so with this in mind let's actually connect to the database from the handler and do some stuff how do we do that well let's make it so that we read a visitor from the database and write our visitor ID and it's going to be a simple service but it's going to give you all the building blocks that you need to actually create your own complex services what we'll do is we have this visitor ID that we set with zero and then I want to connect to the database and run a query row as you can see I don't need to type the full name of the function or even all three little things I can just like you are and that's it and now I need to type my query because it's going to be a bit longer I'm gonna split it on multiple rows so let's do that and start typing so it's going to be insert and goal and automatically knows that I'm connecting to a database to run a query so I should get completion out of it and this is available for sequel X and the standard database sequel package but improvements are welcome so for any other go package that handles database interfaces let us know in the comments on our blog post or send us an issue and tell us if we need to support another package as well ok so back to our writing code we completed sequel that's easy nice but what happens next is that I need to complete visitors and the ID knows that for me so I did that and then what can I do here is that well the idea automatically knows the database field since it had to index them earlier and I kept completion here as well so it's pretty much writing itself at this point almost and I'm gonna complete with now and I'm also going to return the ID field because I would like to read and reply back with that off yet cool so that's none let's go back here and say we want to insert the user agent right so are you a and after this is done well let's make it on the next role to easier to read and I want to scan this into our visitor ID perfect and let's handle the error here so it's gonna be just our so I don't need earth to in this case and when I want to handle this error I definitely don't want to throw a fatal error here I will probably just want to return something like the internal server error or something like that so it's gonna be right header status internal server error and it's gonna be let's write a message to power clients saying something like internal error now that this should be a slice of bytes but I'm too lazy to write that so I like the idea in the back for me and I'm also jump back one one row in type of two so that well I handled that error and then I go back here to actually be able to say well this is unhandled how do I handle it well I have the shortcut here I'll shift enter or I can present link and I handle that er cool so that error is handled now and we can return from here let's make this a bit easier and let's say write a status of okay here and what else can we reply well we can reply the visitor ID right so let's convert this to a printf as well and well I should give a parameter and then go back here and so on but I can do all in one step I can go back here and I say add formatting string argument so this is going to add a formatting string argument based on the type that I have so in this case I'm going to say visitor ID and well that's it I can navigate with 50 to the next error and say well this is redundant I don't need it I can just delete it and I think that's about it like we have what would look like a micro service like a lambda service if you want it connects to a database it handles a function let's see if it runs right so let's deploy it to do that let's go to our webchannel file and this is not an error it's actually our web double file you can see it here and it's up colored as the database yellow file because it's empty so I'm actually going to write our alternate this deployment here and I know this can be complicated and so on and especially if it's your first time using kubernetes it's gonna be a bit scary it was in my case but I can just say cake depth which is our life template for communities deployments and we have a few others as well like there's service and config map and so on but we need k-dub in this case and let's say I'm gonna pipe this as web I'm gonna name let's give a name to this perhaps something like worker depth okay let's go with dr. death like this and I don't want to pull the image I will say this to never so with the communities plug-in you also get some functionality that you are used to writing go code and it's applicable to this part as well and once you learn how to use it in Ingo you can use it in other languages all go so I have the container now I also want to have a port that we expose right and some environment variable that we said we'll expose so let's go with the environment call this DB host and let's call this value well I know the value ahead of time so I'm gonna cheat a bit on this one dr. Dave and what I'm going to do now is I'm gonna go here and say I want to complete the port and my god container port is going to be a key and that's for now it should be fine everything else is okay the other thing that I need to do and this is where we see our multiple definition in a single file feature for Humanities files I want to use a humanity service so just like that I rotate abilities deployment all I need to do here is be careful in the ports and for example in this case I want to use a node port yes I want to target the port 8080 I want to have a node port of 3800 and let's give this a name as well because why not and call it web Airport okay cool so my deployment is done let's see if this runs one button again and you see these in other places are like the main function or the test functions and I'm gonna create that but I don't have anything to deploy right there's no docker file that I created or docker image that I have run and built into a container so what should we do now well let's go and actually build our docker container let's go to the dockerfile and observe the docker file this is more or less of what peeps and the docker file would look like the only thing that I've added here is the effect for rendering because I want to use the vendor in support and then I'm using a multiple layers for this file I'm using multiple files into a single one so that I have everything compacting I don't have to deal with deployment and run files in this case because we are deploying to communities we'll just need to run this so to build this sorry and to do that we can go here and say build docker but let's configure it a bit so that it gives us a bit more information so let's say this is the darker death run configuration I do not want to run the build image and I want to use this as darker give the total - depth sorry with the latest version here cool so when I hit from it's going to run so I'm going to close this and if I go back here it's gonna say build image for dr. death now we'll wait a bit and you may say well you said that there is a mod file and so on but there's you know mod files right like there's no no vendor folder which is correct you'll see that well there's a problem how to fix this well you can bring up the terminal in the IDE and let me make this a bit bigger or use the same shortcut pass before we view mode window to make this a full window and let's say the vendor that's it if I look our IDE and bring up the vendor directory all our dependencies are there and I can be sure that everything is ok cool so let's go back to our file and try once more now our docker server we'll do the build process for us and so on and while we do that we can actually have a look a bit at the total plug in and observe that we have both images and containers running and when the build has completed successfully or not or we'll see that the images here will give us a bit more information and we can see the build blog cool so this is done and if we drop back to our service let's see if it picks it up automatically or we can see that yes it did like it literally worked so our service work works how can we verify this well I could go back and open a browser and so on but I don't particularly want to do that so let's say I'm gonna use the navbar again and I'm gonna say a new file HTTP request and the HTTP request file will require name let's say check what this HTTP file allows us to do is it allows us to run request HTTP request straight from the ID and we get a bit of assistance as well here so you can say HTTP or I want yes HTTP localhost here and I want port 8080 because that's where my service runs and I think that's about it I don't want any other headers and so on but if you are used to more with the curve syntax you can say compared from curl and this will convert the curl syntax into its syntax or you have examples which allows you to see examples so anyway let's run this use alt enter run and this is actually not gonna work and it's correct it's not gonna work right because I have the run report here not remembering which port I put in my web channel file I can invoke the recent locations and say filter by the webcam on file and see that oh I actually have the note port of thirty thousand eight hundred okay so let's switch this a bit here and switch our port correctly and when we run this perfect it works I get back a response although it doesn't look like the one I'm looking for like I'm expecting to get a two hundred everything should be fine what we can see here quickly before we switch to a way to debug our code is that we have the HTTP reply headers we have the message body and it automatically would know how to use JSON for example or HTML and highlight it as such and we have a bit of status at the end of the response just to give us a quick overview in case the response to jump out of the window and would require scroll and so on so we know that it's a 500 it took a bit of time to reply and well the size of the reply cool but well how do we fix this so it means we have a problem in our application and I guess this is the time where you bring up a debugger right so the way to debug this would be to switch back to the main file right and say well kind of thing that bug is here at least I can catch the ball here and how can I do that well we can put a breakpoint on this line right because this is where the condition happens but if we don't want to for the debugger to stop our request if error is indeed new we need to invoke the conditions for a breakpoint and say just stop when the error is not nil otherwise continue and well error is not nearly as a condition suspend the breakpoint yeah all looks good completion work as expected right what else do we need to do well for this case if we are running a debugger we need to adjust a bit the dockerfile and I already did that ahead of time with the dockerfile debug what it does is it fetches delft from the internet perhaps you would want to run this in a more stable manner and not from against master as I am here and then it just changes with the image so that we expose the port 40,000 and changes the command attitude run to actually run Delft right don't worry if it if you cannot copy paste this app right now how this will all be provided at the end of the webinar in form of a repository cool so we did this let's edit our configurations and change the darker configuration that we have here clone this and say well I want to run this as of debug and I want to have it separate because I want to switch between them whenever I want right I'm going to dockerfile and I'm gonna switch here the name here to be deeper so that we can run different images and so on and we don't have to worry about where an image is built if it's a debug or not right go back up here again build image building in progress now we have to wait a bit more because as I said I'm actually downloading Delft right now from the internet so that's great thing to do during a live webinar but if all goes well we'll see that everything is downloaded and compiled sportingly okay so this works and in in a meantime we can switch back to our deployment for its abilities and actually change it to accommodate for the new image that we are downloading so here we need to change this to debug we need to add a nother port I would say so let's change this to a 40,000 as we have in our definition and adjust we would also need to expose this so let's say another port here perfect we have the conclusion that the image was built successfully as it says here cool so if the image is built successfully let's go back here and use the port 40,000 we will target the same port and we want expose this on the north on a different note port and in this case it's going to be in fact 2,800 M for let's say and we give this the name of the port so that we remember what we are doing and yes we could have a different deployment file but for the sake of simplicity it was easier to reuse the same thing let's apply this again to our cluster and we can see that the pod is already up and running while the other one will terminate in a few seconds while this is terminating we can also go to here to run and edit configurations so the thing as we did before we find action and we can say well add me a new configuration and in this case we want to say a goal remote and the remote configuration will allow us to connect to delve in the serratus cluster right so let's do that we have this and unfortunately it seems that I cannot remember the port I think it was thirty thousand eight hundred I'll show you a different way to solve this problem whenever you are start like me and that's writing test ok valve is configured if we switch our services and do a refresh will see that our web application is deployed okay all seems good let's go back to our main file and well let's debug it so let's say debug right okay now we see that debugger connected and again we could pop this into a different window but let's keep it like this for now and let's run a request so if I go to our check file here and I say run I see the debugger stopping and it will it provide any information or not let's see if I inspect the error value here it says scan error column index oh ok so there is an error and I think where I know where the ER is when I scan this I should have used the pointer and not the direct value code so how do we solve this problem like how do we make sure that it doesn't happen again well let's write the test for it and you'll say well you just wrote all the code in the main function like we I don't do that it's not something that I work in my code and I agree we can split this into packages how to do that well first let's extract this from here using the refactor base and it's going to offer a satirist acting up reflecting options including the extract method and I just want to extract the closure not the whole part and let's call this with a different name and let's call it home handler ok cool so this is a bit better now it's not the greatest thing but we can at least test it right because it's a separate function out of the main function what be better well better would be if we actually take this and say move it to a different package okay and let's say if I move this to a different package where should I move it well we we can have a package that is called a handlers for lack of a better word and let's call this file home just press refactor because I know it's well it's not gonna work obviously I just wanted to move the home handler which is not exported to a different package so that means I couldn't have moved it away and still reference it right and you know lab Holland told me that you know it's like are you really sure you want to do that no I am NOT and now I get an error here that yes this is a function that requires the home handler so I'm gonna export this and I'm going to refactor it again and this time I could actually refactor it okay cool what errors do I have here so if I do here using the next select there it's gonna tell me well there's no comment for this so let's add a comment and it's called is something like handles thing home page but I think it's something that we can do a bit better like don't particularly like that bringing this home handler which is in the handler package so if we go here and invoke winning and this is the direct shortcut as opposed to me going through the refactor days so it's just one thing but I would like to change it to home and now it's gonna actually look in all the projects and so on for for this since I'm using go modules there's not much to look for and it tells me that hey there's a home handler in your mail file which is great because I haven't had to touch the mail file but you can also change this from your comments and this is actually useful I'm gonna say yes I want to refactor that usage as well if I wouldn't I would just press Delete on that and that's it cool let's jump to our main file to see that is it there or not and what I involved here is the recent files window I can't make it any smaller for you to see the shortcut but you can see all the shortcuts in your IDE so everything looks good home handler is here I have the correct packages imported everything looks good let's try to test and because we are near the end let's quickly write the best my country factor to tests right my person ho nice picture to refactor into testing so what I can do is I can say generate and besides all the other implementations I can say test for function and this is gonna write a test for me and it's gonna use the table testing approach so if this is something that's new to you there's a great article on the goal and coloring blog about this but I like the gist of it that we can put our test in here and because we are in in the interest of time we are running out and I would like to take some questions from you as well I'm just gonna reuse the test that I already typed for fir this here coke so the red code you know here it's because I have the sequel Mach package installed and once I have the sequel package installed I can synchronize the project again and everything will look at a call so let's right let's run this with coverage because I want also want to see what's the coverage that I have right and the Gopher will compile all the best for us and it's gonna try to run them so let's see what happens and oh no I have an error how that would happen well let's see what the error could be could it be that it received the internal error if we go here and dig deeper yes it did so well let's fix the problem that we we had in in the beginning and how do we fix that well let's go back here quickly in our home and we said that we need a pointers here and it would be nice if the idea would be able to run the test so after I do the change right so how can we do that well let's go back to our test file and if you see the run panel here there is a button auto test so if I toggle that and I then go to the options for that and say well the delay I want to be one second you can make it bigger and smaller as you need let's go back to our handler again and run the test after I do the change and without me touching any keyboard any other shortcuts or anything like that with this has run now there is a different error that I see I wanted the home handler let me clean this up a bit so I wanted a the handler to return Jason but I've got a string let's quickly fix that as well oh and as you can see the coverage is also automatically imported into the adn shown and I can see all the green stuff indicating that yesterday test went from there or the red stuff that note the test would start there so I can hide the panel from here so let's convert these two adjacent quickly and that's it you can do that by using the inject language and I'm going to say Jason and at the end of it I don't want to type in in this one so I can say Eddie Jason fragment and I will say something like this take the content from here start typing status so how does this need to look like status 200 ok Martin Hart code is and you see the gopher trying to run the test for now but yeah and I want to have the message here to actually be what we had earlier perhaps if I would put it in quotes that would be better and Kadam this is it we have artists running I have the coverage displayed I am covering critical in terms of handler of course I haven't wrote the test for the feigning part let me close this tab be it and make this a bit bigger and have it go away so everything looks good and the last part as I said would be for me to share the project with you so what we can do straight from the ad is share project and github and now I already configured the connection to github because I also have to factor out the negation and so on so I don't need to make you wait for all of that and how what I'm going to do right now is share it on github with you it takes a bit of time because it needs to make sure that you know we pull the repository names and make sure that when you're tightening it's not gonna be a problem and well basically we can say go micro service women our origin perfect and share so the Gopher will now go and say yeah do you really want to commit all these files and so on I'm gonna say yeah pretty much sure why not I want to commit the idea folder as well that's fine I want to commit the handler won't come in the vendor folder because it's gonna be easier to test the Sun and all the files in here and I'm gonna say add what it also does during this ad and push operation is that it's gonna also run your affinity for me so all my files will be automatically formatted and so on and at the end of it I'm gonna receive an a link to the project on github so if I open this one here in my browser you'll be able to see the actual project here so everything i coded right now our life is now available for you to download with that said I think we are done for today for the presentation and we can answer some questions thank you for having me today let me bring up the question interface and I'll see where we get some questions to answer to people and I'm gonna dislike meanwhile so that you can actually see see this okay so there are some questions about the scaling and so on I'm using a very poor scaling and this is mostly for presentation normally all the windows would fit in and you get a nice ID but as a reference I'm running on a 250 percent zoom in into the IE and then I increase the font to double size [Music] okay let's see if we get any other questions from the audience on here so just luckily on my Windows machine in this case but you are able to connect to a different doctor service so for example if I would go to the settings or preferences and type quickly here well I don't want the plug-in ok that's fine doctor here in build execution in deployment there is a opportunity for you to define which docker environment you are using you can name these you can have as many as you want and you can even define if it's a poker machine or like you have a TCP connection and if you are using certificates which I highly recommend for your production environment I would recommend that you also configure this and in my case the docker server is just the default 20 on Windows what else so there are some questions about some libraries in go that are perhaps are in libraries and I'm gonna say yes there are all but for this demonstration I felt that it's enough to to handle all the cycle code and so on using just the data basically and in this case equal X package which I find it pretty nice too to help you organize and so on it's I would say halfway through being an ORM but if you need something more like hibernate from Java or doctrine from HP there are similar packages that you'll be able to define in the community yes okay how to test a file upload with the HTTP file well there are some examples with that that so if we go back to our check file in here you'll find some links and you'll see at the request at the moment file convert from open logs and son and there's also a wealth of information on our help page so if you go to our manual Enterprise that come slash help search go you'll be able to find all the information for how to run HTTP files ok so the next question then is there an integrated panel interfaces for running tests on Golant or sure should I just open a terminal and around go test as you can probably saw in the presentation yes you can run no tests from within goal and you can also use shortcuts which is something I haven't really done for that for the presentation like you'll be able to see the fur cut attached to running this year you can configure your own shortcut if you want to run with coverage instead of just simple run and I've shown how to run the auto test so that you don't have to worry about that and so on okay thank you the next question how do you connect the DBM on file with docker so the DBM file basically contains just a reference here in the name of the image and I'm using the standard poster image for this I haven't done any anything special and so on and what this is what this will do is that because I have the full policy set to if not present that means that it's going to pull the image if it's not present and if you're not sure what the poll policy means you can always use the quick documentation feature in any of the tags here and in this case it's gonna be giving you some documentation about what it is and also give you some references for the actual kubernetes documentation and yeah in this case it's going to simply pull the bosphorus image if I go back to our services window here and I have a look at the containers that are running and I apologize if you see any niece named docker containers that's not ref for you you'll be able to see that there's a log for these and there's also a properties you can see the environment variable that I'm using so the username password and so on if there are any volume bindings for this and where there are important links and so on and so forth so you're be able also to actually browse the container if you want and there's a there's an article on our blog on how to actually do that and browse the contents of your docker container okay great thanks and next question why do you why didn't he use FMC but a combination of FMC printer fire FM seadogs printer file is there any performance or style concerns so I prefer to use them depend on the context and in this particular case I don't think there's any particular implication in the speed because well it's gonna have to do basically the same thing anyway so if I would write to this using the write feature or if I'm passing this as a parameter and then using F print it's gonna be the same same thing it's just a bit neater to write and it keeps the code a bit more compact so yeah optionally I could pull this one out from and I would say introduce a variable and let's say yes I want the whole part and let's call this a message to make it a bit easier to see and perhaps this one could be a different constant and so on so like I would say in this constant and say here message well let's call it msg because I have a not very good talent on naming things okay yeah thanks for such clear understanding of that and the next one is why the service name was under the port's sorry which yeah I have to come back on this one uh if that's okay yeah I'll answer like we'll answer all the questions or if you don't don't have to pay more so on to go through them right now so no worries your question will be answered okay the next question how does the introduction of models in go 1.0 affects the kubernetes part what isn't about that well it doesn't really affect the the way you deploy services to communities well what it would allow you to do is have a breakout of the go path and just write your project anywhere in your system so like you don't have to necessarily put everything under go path anymore which is great if if you ask me and if you're coming from other languages it's going to feel natural for you to do but for clarity's there's nothing special as I shown when I was actually deploying the dockerfile initially there's a vendor flag that you can still use so if you used to the veneering approach in the three modules world you can still use that and have been during and if you don't use that then you basically have to get your dependencies from the internet as well which you would do anyway in go path it just makes things a bit simpler to to develop and like you see here I did not have to worry about all putting this there into the towpath making sure that I'm under go path and so on I'm just as in the standard go image to do all the building and so on okay thanks and the next after asked that for plane with mini cube I'm using VM the driver or nun which works only with pseudo rice so I can see any coronaries namespaces with Golant kubernetes plugin is there any way to see them yes so the way to see them would be to tell us about that and we'll take it to our colleagues in other communities for you if there is no open issue then I'll create one or my colleagues will and we'll get back to you either with a workaround or with the issue link so that you can interact that unfortunately I haven't used that particular system to deploy in communities so I'm not really familiar with with that that's why I'm saying it's best if if you tell us about it and yeah you just told us so we'll get back to you on either or workaround or something like that Thanks the next question could appear show us how to debug and also is there a way to grab unless the logs cube pods yeah I shown how to debug that so the it's fine if engine censored as for grabbing the logs let's say I'm going to go here to the pod blog here right click on it and to just say hey pull the information pull the log and there are also a couple of plugins I'm not really sure if they they work with with the output here it's called grep console and idealogue the might work I need to look into that so tell you if you can actually grab for the output or not okay thank you and the next person for web development food you're coming down with plain vanilla go or use a framework like AHA else can you please recommend any good along in libraries if I would recommend development with a framework well that's a debated topic in the NGO community I would say if it's easier it depends on when you're starting with go or you're more experienced to go in the first thing the standard library is what I've used today to build the service so if we look here it's not that different from what you would write in your framework maybe you would want to use the HTTP route or something to have a bit more flexibility on the roads themselves that being said there are frameworks that for example Jean Vigo or buffalo and so on and I'm just naming a few out of the top of my head right now I think there are far more out there that will help you get started so if you feel that a framework is the way to go for you and get started with development no offer it that that's fine just make sure that you also check out the standard library features because sometimes you might not need a full framework experience so to speak to get the service up and running okay great thanks next question shouldn't we use JSON dog marshal instead of handcrafted one I assume it will be safer even in the IDE nose and house in JSON files oh yeah sure so the you totally could take the JSON responses here where is it and just marshal it and so on but for convenience I type the data like I could always say pipe and then let's say msg why not let's go with that and then I would say something like status and then this is gonna be an integer and I know it's gonna be a JSON template right so Jason status and I can also type the message here so string and then I want to use jason here as a message so now I could definitely say that yet message is actually a part of the of these I could say fuel fields let's say with 200 and I want to move the initializing part from here all the way to here right and then instead of MSG I would probably have whatever my message was right so hello visitor and then visitor ID right and then that and that's the rate one of the visitor IDs because we actually don't need two of them so yeah I could say that Oh should I do it well maybe next time I'll do the haps instead I'm not sure okay thanks the next question is more requests and a natural asks us to provide your life's in place what do you think about that sure I can provide that the only life template that I really use right now is the one that you can find here on they're all like templates in this see it's easier if I use search filters quickly so here and there's a bunch of others that I have sorry for the screen again but D BDS is here for example and there's an upcoming webinar when I'm gonna actually teach you how to write your own life templates so there's no necessarily need for copying just my templates you can actually take your own code and converted templates and so on okay the next question is why did it shows a JSON error in the end Jason error Indian well because it wasn't a Jason so I have to format it as JSON and so any of the response and yes maybe next time I should probably go with the Jason I'll confirm it okay yeah we also have some requests to share share their oral here can we do this oh yeah sure oh so let me see if I have the browser open again it's under my github account fine let me see so it's under deal sniper on github and it's gone major service webinar but me bigger so there's no question about open API swagger which I've seen it been sorry for taking this straight out of the pile yes there will be support for that in 2020 point two will announce 2020 point two sometime in the future there's a board post about the features that you'll see up coming in in that and what we plan to work on for now I think you will have to use IntelliJ IDEA ultimate if you want to get that plug-in working and next question what is the best way to handle the be close connection and go so DB close connection well it depends on the library you're using and how you are using it I would say that if it's possible and you can do it always try to close the connection as soon as possible because for most of the libraries it will return it to the pole to the connection pole and then it can be reused and so on but then again it also depends on the application and if it's better to keep it open or not if you plan to do more queries the only thing that I would really advise for is that if your code can panic and for example this is one of the reasons I'm using sequel X it's that it actually does all the clearing for me and so on and I don't have to worry about all of these it's gonna be the idea of like close it as soon as possible with a defer statement so pipe as soon as you open the connection I defer to close it after you check if the connection is established of course so you can say defer close connection and then move on with the rest of the code you yeah next question are there any ways to run tests automatically before committing to the hub uh if there are test ways to test this well I actually don't remember so let's see if we open up the economy changes and what you see here is the new panel format for commits but it's not necessary to use it you can switch back to the old one so it does not seem that we are able to run tests I guess that's a good feature request to run the test before we can perform code analysis and as I said you can perform go affinity so you don't necessarily need to run save in fact if you notice throughout the webinar I did not use save at all because the ID does that for me anyway and I don't need to run - to be unsafe but I can't commit on informat unsafe right share the plugins you installed so can you do that okay so let's go here to the plugins so I have the Gopher plug-in which will make you like it's probably the best plug-in ever it's gonna make you the progress bar into a cover every gopher should have that I have to keep promoter X but it's disabled because this would add a bit of noise I highly recommend this plug-in and please use it if especially if you start learning the IDE what this will do is this will give you a possibility to learn shortcuts as you use your interface with your mouse so if you're new to the idea and want to learn the shortcut oh let me restart the idea while I talk about this you'll be able to learn that and I'm gonna show you shortly how the plug-in works let me touch the ID back so they'll go for progress bar everything that you need and we are back on track while the Kaufering loads let's go for other plug instabilities to plug in that I installed as I mentioned before not all the plugins are compatible with our life install so some of them still need a bit more work either from our side or from the outer side the Mac OS key map so that you can actually see the key maps when I interesting shortcuts and so on I have the make file support no J's because I sometimes have to do that presentation assistant is the one that brings the shortcuts that you're typing in so on at the bottom of the screen and that's useful you should do pair programming so that's gonna be useful properties files because I sometimes need that put above for an upcoming article rainbow bracket is another plug-in that I like and it makes all the colored ring brackets and so on really cool plugin fast time management time tracking in total and then probably that's it like there's not much more that I downloaded you can quickly filter using download and yeah it's basically the same same plugins that I mentioned first are bundled and thanks for in the next question another asked us to imagine if we want to divide a project in to micro services and the first micro service is responsible for sign up and log in and the second one is responsible for interaction with database houses - macro service this will communicate will after have to use two different projects folders with each project having their own model files yes I would say yes if you have to use different services go for two different projects using your modules unless you go for the idea of mono repository with one it was to be to rule them all but in that case you will have different issues to build up the dependencies build the applications whenever you want to give and apply them and so on personally I think that if you're just starting with micro services go for the one repository per application until you figure out like what's the correct boundary and so on and then try to see how that works it's going to be easy to copy paste a pipeline you just need to change the name of the repository they're deploying hopefully especially if you like I said in the beginning if you template some of the files like the docker file for example that can be templated that's fine I call this the server binary so it doesn't really matter like what I'm building it's gonna be server anyway and yeah it's gonna make things a bit easier to figure out in the beginning okay the next question is do the top four has the complete set up pose a environment to follow like tutorial except for the plugins I've just shown and the fact that I entered the same mode here I will show you some other tips and tricks on how to customize the interface but it's the default IDE I'm running the default key maps we have the JetBrains mono font the only thing that I did enabled was the font ligatures and that's the thing that transforms your fonts into using exclamation mark in equals to something like so instead of this and that you get the equal sign bard and that's it like I'm running pretty much the SPARC ID right now but if you would go on our website download it install it and you'd have the same environment as I have almost download the Gopher plugin and the next question are most of the action Dewey Hughes cowered by shortcuts do you mostly use keyboard yes most of the actions are covered by shortcuts and there are a couple of ways to learn them for example the plugin that i showed earlier keep promoter X it has a feature here which actually prompts you like it brings up a message and says hey you've used the git command a few times here's the shortcut for it but if it doesn't have a shortcut it's gonna say well let me actually find the panel we've got a shortcut what would be working for motor exchanges it doesn't name itself right so there's a shortcut for heavy panel I'm not liking right now it would prompt you for setting a shortcut with key promoter X you'd be able to like learn the shortcuts that you're missing and let me make this a bit bigger so for example Toby I've pressed that a lot or better said I could I could press that a lot but I can use the mouse a lot and well maybe it's time to improve that can reset the statistics and so on besides the promoter X the IDE also can help you with the help key map reference and this is going to give you a key map reference of the IDE combinations and so on and what were you what we feel you'll find useful this is on my computer so no need to copy the address but it'll be on your computers as well and I highly recommend the productivity guide so if you don't know about this help productivity guide will actually be your best friend in learning the IDE features along with the next feature that I'm going to show you what this does is basically it tells you so there is a feature called basic code completion and you can use control space to it address it so let's sort by since I used it let's start by something that I never used like the Saran statement reef and now I have more information and if I look at how this looks like and what it does then it allows me to learn the ID shortcuts so what I recommend is besides the tip of the day which shows that the IDE start go to help productivity guide and have a look at that it's going to help you understand features of the ID that you are not using for example go to symbol I don't use go to symbol but maybe I should and finally the other thing that allows you to learn the IDE and it's something that we actually added a couple of releases ago if I remember correctly and let me close this project as well and it's gonna be the tutorials section here so let me close all the projects here so under the tutorials section you'll be able to find various tutorials and it features that we release with each new version of the IDE and what you can do is for example let's take this one twenty twenty point one and it's going to allow you to understand the features that we've released it's not a full list of all the features that we released in a release but it's a good start to like give you what we think are the highlighted features for that release and you can see all of them here you can also navigate for example hitch-hiker guide and see another bolus of features and so on so forth thanks Lauren next question how do displays a pop-up to show the parameters type and name of functions okay let me click somewhere in the code and the shortcut is parameter info or ctrl P or command P on Mac OS and sometimes it will pop up automatically when you or when you actually type so F&T type is not a problem are you involved in it okay thanks and a couple of questions more just a second okay great question is there any good way to work with my Garland yes there is we actually have support for help in Garland and I will try to to bring up the help on this one because well I don't have anything right now to actually show to you so if you search for goal and help you will see a blog post from our colleagues in the IntelliJ IDEA team and what you'll see here is applicable to garland as well because it's gonna be used by the same to brand it is plug in and basically when you install join it is plug in you get help support that's all it's something that I could have mentioned and what you'll see here is the support that we have for helm at the time of release so this was in 2018 be told but if we go here well this is still help let's go to the timber native support here so you'll be able to get more information in in the help part so generator from help go to annuities and hound support and you are able to see the information we support custom research definitions as well I and the last one question did we deploy Postgres on localhost as a separate docker container yes so this let me switch to the project itself so if I go to the project again when we deployed the database here so when we were in the database ml file we actually deployed this under communities pastor so if I were to bring the window back again and connect to the docker host I would be able to see that and I can see the workload as well here so I can see the database working and this one was separated as sorry this one is the current database yeah so thank you for him thank thank you everyone for joining us and see you soon on our next webinar thank you thank you for having me today and for being with us today you
Info
Channel: JetBrainsTV
Views: 22,565
Rating: 4.8562875 out of 5
Keywords: JetBrains, software development, developer tools, programming, developer, build a microservice, build a microservice with go, Build a Microservice with Go and GoLand, go and goland, microservices, golang, Kubernetes, PostgreSQL, build a microservice from scratch, micro-service, code coverage, Kubernetes cluster, Florin Pățan, go language, go programming language
Id: arZiFSerU1k
Channel Id: undefined
Length: 88min 17sec (5297 seconds)
Published: Tue May 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.