Video Recording and Q&A of Build a Microservice in Go with GoLand in an Hour webinar

Posted on by Florin Pățan

Last week we hosted our first webinar, with the theme of Go Microservices development in GoLand. It was great to see so many people attending, asking questions, and giving us their feedback. To that end, I’d like to say a big thank you to everyone who participated, as well as to our JetBrains team that made this all possible.

During the webinar, we promised to reply to as many questions as we can, and that’s what we’re doing in today’s blog post.

Here’s a quick recap of the presentation:

  • We used a basic “Hello World” application using net/http as a base project.
  • We then deployed a database in a Kubernetes cluster.
  • We linked the IDE to the database, allowing us to index the database structure and provide code assistance later.
  • We modified the application to connect to the database.
  • We deployed the application to the Kubernetes cluster and debugged it.
  • We refactored the application to make it easier to test and organize the source code.
  • We used code generation to create tests for our application and prevent bugs in the future.
  • Q&A.

If you missed the webinar, don’t worry, you can find a recording of it here:

The source code created during the presentation can be found here: https://github.com/dlsniper/go-microservice-webinar

From the questions we received, we picked three respondents to receive a free license. We’ll be sending those out to the lucky winners shortly.

We divided the questions into four categories:

Regarding the environment used in the presentation:

Gopher: Is it doable with the K8S included in Docker for Mac, or is another type of K8S deployment needed?
Gopher: Can I connect it with my local minikube?
Gopher: Is Docker running locally on Windows?
Florin: This will work with any Kubernetes deployment. In my presentation, I used Kubernetes on Windows.
The plugin will connect to any Kubernetes-compatible server, as long as the .kube/config configuration defaults to it and the API is compatible with the Kubernetes API.
For Docker on Mac there shouldn’t be any special requirements.

Gopher: How hard would it be to move this application to the GCP KE?
Florin: Not very hard. The only problem would be in how the database is initialized, as the file is loaded from the local machine. You’d need to create a container image with all the information needed or have the application create the initial database layout, or do it manually. Then you should be good to go.

Gopher: DB Question: Did you deploy Postgres on the localhost as a separate docker-container?
Florin: Yes, it was deployed using Kubernetes. See our blog post series on this.

Regarding the IDE configuration:

Gopher: Can I view mounted Config Maps in the editor?
Florin: Yes, it’s available under Configuration | Config Maps in the Kubernetes view of the Service Tool Window.

Gopher: Is there an integrated panel/interface for running tests on GoLand, or should I just open a terminal and go test ./... it?
Florin: Yes, you can run tests/benchmarks directly from the IDE. See the GoLand testing help documentation for more details about this.
You can create Run Configurations that are capable of using the same commands that you’d run in the (built-in) Terminal.

Gopher: Is there a way to disable those “parameter helpers” (by that I mean for instance when I type os.Getenv(“X”), GoLand shows os.Getenv(key: “X”))? While I find it *amazing*, I’d like to be able to disable it when, for instance, taking a screenshot off my code so as to not confuse people not using GoLand…
Florin: Yes, they are called Inline Hints and they can be disabled using Alt+Enter or by right-clicking on them. Alternatively, you can use Settings/Preferences | Editor | Inlay Hints.

Gopher: Is there any way to delete the K8S deployment and all it includes from within the GoLand UI?
Florin: Not at the moment, watch this issue for updates.

Gopher: Will you also share your live templates?
Florin: I’m currently using a single live template in the presentation. You can find it in this repository. If you’d like to learn more, check out the GoLand Live Templates guide. You can also join our upcoming webinar on GoLand Tips & Tricks at the beginning of June, stay tuned for further details.

Gopher: Are there any ways to run tests automatically before committing to Github?
Florin: Not at the moment. We have an open issue about this but it’s not on the roadmap yet.

Gopher: Could you share the plugins you installed?
Florin: I used the following plugins during the presentation: Presentation Assistant, Rainbow Brackets, and Gopher.

I also highly recommend Key Promoter X if you are just getting started with the IDE or if you want to learn the shortcuts as you work.

Aside from those, I also have the following plugins installed: Grep Console, Ideolog, Properties, Task Management, Time Tracking, Sass, Protobuf Support, Makefile support, Node.js, and Toml.

Gopher: Which Editor Color Scheme are you using? Is it custom or built-in?
Florin: I use a default IDE installation and in this particular case I used Darcula with Rainbow Brackets and Gopher plugins, see the above question.

Gopher: I am interested in understanding the complete setup of the environment. Is there a tutorial?
Florin: The environment used was set up from scratch. We’ll hold a webinar at the end of June about setting up your work environment from scratch.

Gopher: Does GoLand support OpenAPI/Swagger? Can we do code generation on the IDE?
Florin: From 2020.2 it will.

In the following section, I’ll recommend only packages that I have personal experience with. That doesn’t mean they are the best in their domain, they just happened to fill the needs I had at the time when I used them.

Gopher: Are there any ORM libraries for Go similar to Hibernate in Java?
Florin: There are different ORMs in Go. Off the top of my head, I can suggest you look at https://gorm.io/ or https://github.com/gobuffalo/pop, or https://github.com/volatiletech/sqlboiler. There are more you can browse through here https://github.com/avelino/awesome-go#orm.
I have used sqlx in all of my work so far.

Gopher: For web development, would you recommend going with plain vanilla Go or use a framework like Echo? Also, can you recommend any good logging libraries?
Gopher: What is the recommended framework to use in production for building microservices? like Spring for Java.
Gopher: Based on your experience, what is the best microservice framework, GoKit, or Micro?
Florin: I started with net/http back in the day and then added gorilla/mux on top of it. Most of the projects I wrote use either of these two. That being said, there are a lot of frameworks that you can try. Off the top of my head, I can suggest gin, echo, buffalo, or beego, but you can find a lot more here: https://github.com/avelino/awesome-go#web-frameworks.

Regarding logging, I generally used either the standard library log package or logrus. Some people also prefer zap, and there are a lot of other options here: https://github.com/avelino/awesome-go#logging.

I don’t have any particular opinion on either GoKit or Micro, as they each solve problems in their own very specific way.

Gopher: Do you recommend having a type for response data and a type for the database model?
Florin: Yes, that would make sense. During the presentation, I wanted to show how a JSON string can be quickly written using the IDE support, but in a production environment, I’d probably use a typed JSON response most of the time.

Gopher: What would you use for securing your handler? TLS module or just istio/linkerd?
Florin: TLS handler, but istio/linkerd are not bad options either.

Gopher: Is the ‘HTTP file’ thing unique to GoLand / Go?
Florin: You can use the HTTP client in all JetBrains IDEs, see the GoLand in-editor HTTP client documentation for more information about this feature.

Gopher: Can I code Kubernetes operators in a similar way?
Florin: Yes, you can code any kind of application using the same workflow shown during the webinar.

Gopher: Can I both debug and hot reload the code in a Docker container by installing delve in the container?
Florin: You can debug an application that runs inside a container, as in the webinar.
As for the hot reloading of code, that’s not a trivial task to do, especially in different operating systems. I may publish a blog post about this in the future if there is enough interest in it.

Gopher: Are you able to do remote debugging in remote Kubernetes environments within GoLand?
Florin: Yes, that would not be a problem. Follow the same steps as in the webinar.

Gopher: Hi, let’s say you want to divide a project into 2 microservices. The 1st microservice is responsible for sign up and log in. The 2nd Microservice is responsible for interacting with the database. How will these two microservices communicate? Will I have to use 2 different project folders with each project having its own two Go module files?
Florin: You can expose an API for the two different services to communicate with each other. It can be as simple as using a standard JSON API over HTTP, or you can use something more advanced like Protobuf and gRPC.

There is no easy way to tell what’s better, as it depends on a lot of variables. But if you are a small team, or alone, I’d recommend using a single repository with all the sources in it, in a single project that uses the pattern of multiple cmd folders to break down the application into different components. You can read about this in this article from Dave Cheney, specifically the Multiple commands and multiple packages section.

Gopher: Is there a gRPC equivalent of the http request file?
Florin: Not at the moment, but I created this request for it. Please watch it/vote for it to receive updates.

Gopher: Is there a profiling plugin for mutex contention & memory/CPU in the IDE?
Florin: There is no specific plugin for this as the functionality is built-in. To run these profilers, you have to write a test or a benchmark. See our help documentation on this.

Gopher: How about the CGO file, can GoLand handle it as easily as Go libraries?
Florin: At the moment GoLand does not support editing C files with the same level of features as it does for Go. Basic highlighting is supported for C, and you can reference C types once they are imported in Go. If you need to work on C sources, then please use CLion, our dedicated C IDE. Please note that it does not support Go editing at the moment either.
However, we plan to improve the editing experience for some use-cases, watch/vote for this issue to receive updates when we’ll have any.

Gopher: If you are working with multiple databases, can you specify what database you want completion for in your Go files?
Florin: You can choose to select which database to use using the database name prefix in the queries. E.g. for db1 and db2, you can refer to queries like db1.table.column and db2.table.column.

Gopher: Is there any good way to work with Helm via GoLand?
Florin: Yes, Helm support is present once you install the Kubernetes plugin. See our help documentation about this.

This is all for now. I hope they addressed all the other questions that I couldn’t answer during the webinar.

There are a few other questions that I could not address here as they require a bit more details from the person that asked them. I’ll reach out to you in the coming days to help you out and address them as well.

Thank you once again for your participation and see you at our next event. Until then, please let us know your thoughts in the comments section below, on our issue tracker, or tweet to us @GoLandIDE, or to me @dlsniper.

Comments below can no longer be edited.

9 Responses to Video Recording and Q&A of Build a Microservice in Go with GoLand in an Hour webinar

  1. b4 says:

    May 20, 2020

    I watched this live and was really let down by it to be honest. It didn’t cover building a Microservice with Go and a GoLand, it was basically 5 minutes making a hello world http example and then an hour of talking about features that exist in every IntelliJ based IDE, nothing specific to GoLand. You can change your progress bar to a gopher with a plug-in though, so I guess that made it worth my evening…

    • Florin Pățan says:

      May 20, 2020

      Hi b4,

      Sorry to hear this was disappointing for you.
      What would you like to see improved in the presentation to make it worth while?

      • b4 says:

        May 20, 2020

        Probably more of the “Making a Microservice with Go” part of the title instead of entirely the “with GoLand” part? The point of the webinar was to sell GoLand to people, and that’s perfectly fine, but the title was really misleading as there was barely any actual Go in this. Maybe “Use the Kubernetes tools built into GoLand and every other IntelliJ based IDE” would’ve been more useful?

        I’m not knocking it, I just feel really betrayed by the title when I wasted an afternoon expecting to learn how to make a Microservice in Go and GoLand and instead I was shown how to spin a docker container up for an hour

        • Florin Pățan says:

          May 20, 2020

          The point of the webinar was to show someone how to use GoLand and do something useful with it, e.g. a micro-service. In this case, it’s a more advanced “Hello World” than the regular ones, connecting to a database, deploying to Kubernetes, etc.

          I understand that this was not exactly what you were hoping for, so I’m asking you for your feedback on what would you expect from it in the future. Say I do a follow-up from this, what should it contain so that it’s worth watching?

    • Ken says:

      May 21, 2020

      FWIW, I did find it useful because I leaned some neat tricks in the IDE.

      The webinar did build a microservice and deploy to K8s.
      Would have been nice to see it use a framework like gomicro or gokit but some people hate them as mentioned in the webinar.

      • Florin Pățan says:

        May 26, 2020

        Ken, thanks for your feedback.

        I have the same question as for b4, if there’s anything else that I could do to make this more interesting, please let me know.

        Would a follow-up on micro-services best practices, or other related topics be useful? If so, any suggestions on what you’d like to see are welcomed.

  2. b4 says:

    May 20, 2020

    I watched this live and was really let down by it to be honest. It didn’t cover building a Microservice with Go and a GoLand, it was basically 5 minutes making a hello world http example and then an hour of talking about features that exist in every IntelliJ based IDE, nothing specific to GoLand. You can change your progress bar to a gopher with a plug-in though, so I guess that made it worth my evening…

    Obviously a free webinar was always going to just be an advert, but this was insulting

  3. Mitch Dresdner says:

    May 26, 2020

    Hello,

    I’m working through the recent microservice podcast and am unable to initialize the PG DB using the provided db.yaml. There seems to be some conflict with the Docker desktop Windows 10 / Kubernetes file sharing which prevents adding the init.sql file. By chance are you using WSL2 Docker desktop?

    volumeMounts:
    - name: db-init
    mountPath: /docker-entrypoint-initdb.d/init.sql
    subPath: init.sql
    volumes:
    - name: db-init
    hostPath:
    path: /c/temp/data

    Instead I added a second configmap to do the DB create tables which seems to be working:

    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: db-create-config
    labels:
    dockerdev: db
    data:
    CREATE_TBL: |
    CREATE TABLE IF NOT EXISTS visitors(id serial constraint visitors_pk primary key,user_agent varchar(250),atetime timestamp);
    CREATE INDEX IF NOT EXISTS visitors_user_agent_index ON visitors (user_agent);
    ---

    ...

    volumeMounts:
    - name: db-init
    mountPath: /docker-entrypoint-initdb.d/CREATE_TBL.sql
    subPath: CREATE_TBL.sql
    volumes:
    - name: db-init
    configMap:
    name: db-create-config
    items:
    - key: CREATE_TBL
    path: CREATE_TBL.sql

    • Florin Pățan says:

      May 27, 2020

      Hi Mitch,

      > There seems to be some conflict with the Docker desktop Windows 10 / Kubernetes file sharing which prevents adding the init.sql file. By chance are you using WSL2 Docker desktop?

      No, I’m using the WSL 1, but I did have some issues in the past with Docker not mounting volumes from Windows. Usually because of the firewall/sharing settings.

      That looks like a great idea to work around those problems. Would you mind sending a pull request with the changes? I’ll be happy to merge them.

      Thank you!

Subscribe

Subscribe for updates