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: spec.go
    path of file: ./repos/easegress/pkg/supervisor
    
    the code of the file until where you have to start completion: /*
 * Copyright (c) 2017, The Easegress Authors
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *
    
func (s *Supervisor) newSpec(config string, created bool) (spec *Spec, err error) {
	spec = &Spec{super: s}

	defer func() {
		if r := recover(); r != nil {
			spec = nil
			err = fmt.Errorf("%v", r)
		} else {
			err = nil
		}
	}()

	buff := []byte(config)

	// Meta part.
	meta := &MetaSpec{Version: DefaultSpecVersion}
	if created {
		meta.CreatedAt = time.Now().Format(time.RFC3339)
	}
	codectool.MustUnmarshal(buff, meta)
	verr := v.Validate(meta)
	if !verr.Valid() {
		panic(verr)
	}

	// Object self part.
	rootObject, exists := objectRegistry[meta.Kind]
	if !exists {
		panic(fmt.Errorf("kind %s not found", meta.Kind))
	}
	objectSpec := rootObject.DefaultSpec()
	codectool.MustUnmarshal(buff, objectSpec)
	verr = v.Validate(objectSpec)
	if !verr.Valid() {
		panic(verr)
	}

	// Build final json config and raw spec.
	var rawSpec map[string]interface{}
	objectBuff := codectool.MustMarshalJSON(objectSpec)
	codectool.MustUnmarshal(objectBuff, &rawSpec)

	metaBuff := codectool.MustMarshalJSON(meta)
	codectool.MustUnmarshal(metaBuff, &rawSpec)

	jsonConfig := string(codectool.MustMarshalJSON(rawSpec))

	spec.category = rootObject.Category()
	spec.meta = meta
	spec.objectSpec = objectSpec
	spec.rawSpec = rawSpec
	spec.jsonConfig = jsonConfig

	return
}