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: meshcertprovider.go
    path of file: ./repos/easegress/pkg/object/meshcontroller/certmanager
    
    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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 certmanager

import (
	"bytes"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/base64"
	"encoding/pem"
	"fmt"
	"math/big"
	"net"
	"sync"
	"time"

	"github.com/megaease/easegress/v2/pkg/logger"
	"github.com/megaease/easegress/v2/pkg/object/meshcontroller/spec"
)

var (
	appSubjectKeyID = []byte{102, 202, 33, 104, 96}
)

// MeshCertProvider is the EaseMesh in-memory, Self-Sign type cert provider.
type MeshCertProvider struct {
	RootCert     *spec.Certificate
	ServiceCerts map[string]*spec.Certificate
	mutex        sync.RWMutex
}

// NewMeshCertProvider creates a new mesh in-memory, self-sign cert provider
func NewMeshCertProvider() *MeshCertProvider {
	return &MeshCertProvider{
		ServiceCerts: make(map[string]*spec.Certificate),
	}
}

func un
    
func (mp *MeshCertProvider) SignAppCertAndKey(serviceName, host, ip string, ttl time.Duration) (cert *spec.Certificate, err error) {
	if mp.RootCert == nil {
		err = fmt.Errorf("not root cert found")
		return
	}

	var (
		ca        *x509.Certificate
		caPrivKey *rsa.PrivateKey
	)
	ca, err = decodeCertPEM(mp.RootCert.CertBase64)
	if err != nil {
		logger.Errorf("decode root cert pem failed: %v", err)
		return
	}
	caPrivKey, err = decodeKeyPEM(mp.RootCert.KeyBase64)
	if err != nil {
		logger.Errorf("decode root key pem failed: %v", err)
		return
	}
	logger.Infof("try to sign serverName: %s, HOST: %s IP: %s, ttl: %s", serviceName, host, ip, ttl.String())
	now := time.Now()
	x509Cert := &x509.Certificate{
		SerialNumber: big.NewInt(defaultSerialNumber),
		Subject: pkix.Name{
			Country:      []string{defaultRootCertCountry},
			Locality:     []string{defaultRootCertLocality},
			Organization: []string{defaultRootCertOrganization},
		},
		NotBefore:    now,
		NotAfter:     now.Add(ttl),
		SubjectKeyId: appSubjectKeyID,
		ExtKeyUsage:  []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
		KeyUsage:     x509.KeyUsageDigitalSignature,
		DNSNames:     []string{"*"},
		IPAddresses:  []net.IP{net.ParseIP(ip), net.IPv6loopback},
	}

	certPrivKey, err := rsa.GenerateKey(rand.Reader, 4096)
	if err != nil {
		logger.Errorf("service: %s generate key failed: %v", serviceName, err)
		return
	}
	certBytes, err := x509.CreateCertificate(rand.Reader, x509Cert, ca, &certPrivKey.PublicKey, caPrivKey)
	if err != nil {
		logger.Errorf("service: %s create cert failed: %v", serviceName, err)
		return
	}

	certPEM := new(bytes.Buffer)
	pem.Encode(certPEM, &pem.Block{
		Type:  typeCert,
		Bytes: certBytes,
	})

	certPrivKeyPEM := new(bytes.Buffer)
	pem.Encode(certPrivKeyPEM, &pem.Block{
		Type:  typeKey,
		Bytes: x509.MarshalPKCS1PrivateKey(certPrivKey),
	})

	cert = &spec.Certificate{
		ServiceName: serviceName,
		IP:          ip,
		CertBase64:  base64.StdEncoding.EncodeToString(certPEM.Bytes()),
		KeyBase64:   base64.StdEncoding.EncodeToString(certPrivKeyPEM.Bytes()),
		TTL:         ttl.String(),
		SignTime:    now.Format(time.RFC3339),
		HOST:        host,
	}

	mp.SetAppCertAndKey(serviceName, host, ip, cert)
	return
}