github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/upgrade-guide/v2-to-v3.md (about) 1 --- 2 title: V2 to V3 Upgrade Guide 3 keywords: micro 4 tags: [micro] 5 sidebar: home_sidebar 6 permalink: /v2-to-v3-upgrade-guide 7 summary: Upgrading your project from Go-Micro v2 to Micro v3 8 --- 9 10 ## Upgrading your project from Go-Micro v2 to Micro v3 11 12 ### Introduction 13 14 As part of v3 we've simplified the development model and consolidated the micro and go-micro libraries. This means that you, as the developer, only need to worry about leveraging the libraries offered in micro. Users of the now deprecated [go-micro](https://github.com/asim/go-micro) framework can follow this guide to upgrade their projects to use Micro v3. 15 16 ### Service 17 18 In go-micro, you would create a service by importing `github.com/micro/go-micro` and using the following syntax: 19 20 ```go 21 srv := micro.NewService( 22 micro.Name("go.micro.service.foo") 23 ) 24 ``` 25 26 In Micro V3, we've removed namespaces from service names, so the above service would now be named simply **foo**. We've also created a package specifically for services: `github.com/tickoalcantara12/micro/v3/service`. Dotted service names can still be used, however the full service name will be required when calling the API, such as: "http://localhost:8080/go.micro.service.foo/Bar", unless the API is configured with the namespace flag. 27 28 The above service can now be defined as: 29 ```go 30 srv := service.New( 31 service.Name("foo") 32 ) 33 ``` 34 35 ### Packages 36 37 In go-micro, modules such as config could only be accessed via the service object, for example `srv.Options().Config.Read()`. In Micro this has been made easier by providing public functions in each package which can be accessed by importing any package, nested within "github.com/tickoalcantara12/micro/v3/service". Here is an example of how you can load config in Micro: 38 39 ```go 40 package main 41 42 import ( 43 "github.com/tickoalcantara12/micro/v3/service" 44 "github.com/tickoalcantara12/micro/v3/service/config" 45 "github.com/tickoalcantara12/micro/v3/service/logger" 46 ) 47 48 func main() { 49 // Create the service 50 srv := service.New( 51 service.Name("config-example"), 52 ) 53 54 // Load the config 55 val, err := config.Get("mykey") 56 if err != nil { 57 logger.Fatalf("Could not load mykey: %v", err) 58 } else { 59 logger.Infof("mykey = %v", val) 60 } 61 62 // Run the service 63 if err := srv.Run(); err != nil { 64 logger.Fatal(err) 65 } 66 } 67 68 ``` 69 70 Other examples of packages which can be imported in this manner are: 71 * [Auth](https://github.com/tickoalcantara12/micro/tree/master/service/auth) 72 * [Broker](https://github.com/tickoalcantara12/micro/tree/master/service/broker) 73 * [Client](https://github.com/tickoalcantara12/micro/tree/master/service/client) 74 * [Config](https://github.com/tickoalcantara12/micro/tree/master/service/config) 75 * [Context](https://github.com/tickoalcantara12/micro/tree/master/service/context) 76 * [Errors](https://github.com/tickoalcantara12/micro/tree/master/service/errors) 77 * [Logger](https://github.com/tickoalcantara12/micro/tree/master/service/logger) 78 * [Store](https://github.com/tickoalcantara12/micro/tree/master/service/store) 79 80 81 ### Running services 82 83 Go Micro services interfaced directly with the underlying infrastructure, meaning they could be run using `go run`. In Micro V3 this has been abstracted using the `micro server`. The Micro server provides a level of abstraction to the underlying infrastructure, keeping your services unbound from their dependancies. 84 85 In practice, this means you need to be connected to a micro environment when running your services. You can spin up this environment locally using the `micro server` command, or connect to the free platform provided by M3O using `micro env set platform`. You can read more about running a service [in our getting started guide](/getting-started#running-a-service). 86 87 *Note: don't forget to run your micro v3 services using `micro run .` instead of `go run .`*