You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: main.go
    path of file: ./repos/magma/orc8r/gateway/go/services/magmad
    
    the code of the file until where you have to start completion: /*
Copyright 2020 The Magma Authors.

This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"os"
	"runtime/debug"
	"time"

	"github.com/golang/glog"

	"magma/gateway/config"
	"magma/gateway/services/bootstrapper/gateway_info"
	bootstrapper "magma/gateway/services/bootstrapper/service"
	configurator "magma/gateway/services/configurator/service"
	"magma/gateway/services/magmad/service"
	"magma/gateway/services/magmad/serv
    
func mainEventLoop(eventChan <-chan interface{}, freeMemChan <-chan time.Time) {
	for {
		select {
		case evnt := <-eventChan:
			switch e := evnt.(type) {
			case bootstrapper.BootstrapCompletion:
				if e.Result != nil {
					glog.Errorf("bootstrap failure: %v for Gateway ID: %s", e.Result, e.HardwareId)
				} else {
					glog.Infof("bootstrapped GW %s", e.HardwareId)
					controller := service_manager.Get()
					if config.GetControlProxyConfigs().ProxyCloudConnection {
						glog.Info("restarting control_proxy")
						if err := controller.Restart("control_proxy"); err != nil {
							glog.Errorf("failed to restart control_proxy: %v", err)
						}
					} else {
						// Restart all magma services
						go func() {
							for _, service := range config.GetMagmadConfigs().MagmaServices {
								controller.Restart(service)
							}
						}()
					}
				}
			case configurator.UpdateCompletion:
				glog.Verbose(len(e) > 0).Infof("mconfigs updated successfully for services: %v", e)
				// Restart all services with updated configs
				go func() {
					magmaServiceTable := map[string]struct{}{}
					for _, service := range config.GetMagmadConfigs().MagmaServices {
						magmaServiceTable[service] = struct{}{}
					}
					controller := service_manager.Get()
					for _, service := range e {
						// restart only if it's this GW's service
						if _, ok := magmaServiceTable[service]; ok {
							controller.Restart(service)
						}
					}
				}()
			default:
				glog.Errorf("unknown completion type: %T", e)
			} // switch
		case _, ok := <-freeMemChan:
			if ok {
				glog.Info("purging unused memory")
				debug.FreeOSMemory()
				if glog.V(2) {
					profile.LogMemStats()
				}
				// write out heap profile if built with -tags with_profiler, noop otherwise
				// to use:
				//    go tool pprof -http=127.0.0.1:9999 <path/to/magmad> <profiles_dir/memory_MMDD_HH.mm.SS.pprof>
				profile.MemWrite()
			}
		} // select
	}
}